Rev 511 | Rev 532 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 511 | Rev 517 | ||
---|---|---|---|
Line 42... | Line 42... | ||
42 | * |
42 | * |
43 | * Read characters from character device until first occurrence |
43 | * Read characters from character device until first occurrence |
44 | * of newline character. |
44 | * of newline character. |
45 | * |
45 | * |
46 | * @param chardev Character device. |
46 | * @param chardev Character device. |
47 | * @param string Buffer where to store string terminated by '\0'. |
47 | * @param buf Buffer where to store string terminated by '\0'. |
48 | * @param len Size of the buffer. |
48 | * @param len Size of the buffer. |
- | 49 | * |
|
- | 50 | * @return Number of characters read. |
|
49 | */ |
51 | */ |
50 | void gets(chardev_t *chardev, __u8 *string, size_t buflen) |
52 | count_t gets(chardev_t *chardev, char *buf, size_t buflen) |
51 | { |
53 | { |
52 | index_t index = 0; |
54 | index_t index = 0; |
53 | char ch; |
55 | char ch; |
54 | 56 | ||
55 | while (index < buflen) { |
57 | while (index < buflen) { |
56 | ch = getc(chardev); |
58 | ch = getc(chardev); |
57 | if (ch == '\n') { /* end of string => write 0, return */ |
59 | if (ch == '\n') { /* end of string => write 0, return */ |
58 | string[index] = '\0'; |
60 | buf[index] = '\0'; |
59 | return; |
61 | return (count_t) index; |
60 | } |
62 | } |
61 | string[index++] = ch; |
63 | buf[index++] = ch; |
62 | } |
64 | } |
63 | return; |
65 | return (count_t) index; |
64 | } |
66 | } |
65 | 67 | ||
66 | /** Get character from character device. |
68 | /** Get character from character device. |
67 | * |
69 | * |
68 | * @param chardev Character device. |
70 | * @param chardev Character device. |