Subversion Repositories HelenOS

Rev

Rev 4153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4153 Rev 4263
Line 24... Line 24...
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup generic
29
/** @addtogroup generic
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
Line 37... Line 37...
37
#include <putchar.h>
37
#include <putchar.h>
38
#include <synch/spinlock.h>
38
#include <synch/spinlock.h>
39
#include <arch/asm.h>
39
#include <arch/asm.h>
40
#include <arch/types.h>
40
#include <arch/types.h>
41
#include <typedefs.h>
41
#include <typedefs.h>
-
 
42
#include <string.h>
42
 
43
 
43
SPINLOCK_INITIALIZE(printf_lock);           /**< vprintf spinlock */
44
SPINLOCK_INITIALIZE(printf_lock);  /**< vprintf spinlock */
44
 
45
 
45
static int vprintf_write(const char *str, size_t count, void *unused)
46
static int vprintf_str_write(const char *str, size_t size, void *data)
46
{
47
{
47
    size_t i;
48
    size_t offset = 0;
-
 
49
    count_t chars = 0;
-
 
50
   
48
    for (i = 0; i < count; i++)
51
    while (offset < size) {
-
 
52
        putchar(str_decode(str, &offset, size));
49
        putchar(str[i]);
53
        chars++;
-
 
54
    }
-
 
55
   
50
    return i;
56
    return chars;
51
}
57
}
52
 
58
 
53
int puts(const char *s)
59
static int vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
54
{
60
{
55
    size_t i;
61
    size_t offset = 0;
-
 
62
    count_t chars = 0;
-
 
63
   
-
 
64
    while (offset < size) {
-
 
65
        putchar(str[chars]);
-
 
66
        chars++;
56
    for (i = 0; s[i] != 0; i++)
67
        offset += sizeof(wchar_t);
-
 
68
    }
-
 
69
   
-
 
70
    return chars;
-
 
71
}
-
 
72
 
-
 
73
int puts(const char *str)
-
 
74
{
-
 
75
    size_t offset = 0;
-
 
76
    count_t chars = 0;
-
 
77
    wchar_t uc;
-
 
78
   
-
 
79
    while ((uc = str_decode(str, &offset, STR_NO_LIMIT)) != 0) {
57
        putchar(s[i]);
80
        putchar(uc);
-
 
81
        chars++;
-
 
82
    }
-
 
83
   
58
    return i;
84
    return chars;
59
}
85
}
60
 
86
 
61
int vprintf(const char *fmt, va_list ap)
87
int vprintf(const char *fmt, va_list ap)
62
{
88
{
-
 
89
    printf_spec_t ps = {
-
 
90
        vprintf_str_write,
63
    struct printf_spec ps = {(int(*)(void *, size_t, void *)) vprintf_write, NULL};
91
        vprintf_wstr_write,
-
 
92
        NULL
-
 
93
    };
64
   
94
   
65
    ipl_t ipl = interrupts_disable();
95
    ipl_t ipl = interrupts_disable();
66
    spinlock_lock(&printf_lock);
96
    spinlock_lock(&printf_lock);
67
   
97
   
68
    int ret = printf_core(fmt, &ps, ap);
98
    int ret = printf_core(fmt, &ps, ap);