Changeset c583970 in mainline
- Timestamp:
- 2009-04-03T08:00:13Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9be1d58
- Parents:
- d6c8ff6
- Location:
- kernel/generic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/console/console.h
rd6c8ff6 rc583970 50 50 51 51 extern bool check_poll(indev_t *indev); 52 extern uint8_t getc(indev_t *indev);53 extern uint8_t _getc(indev_t *indev);52 extern wchar_t getc(indev_t *indev); 53 extern wchar_t _getc(indev_t *indev); 54 54 extern count_t gets(indev_t *indev, char *buf, size_t buflen); 55 extern unative_t sys_klog(int fd, const void * buf, size_t count);55 extern unative_t sys_klog(int fd, const void *buf, size_t size); 56 56 57 57 extern void grab_console(void); -
kernel/generic/src/console/console.c
rd6c8ff6 rc583970 51 51 #include <syscall/copy.h> 52 52 #include <errno.h> 53 #include <string.h> 53 54 54 55 #define KLOG_SIZE PAGE_SIZE … … 155 156 * 156 157 */ 157 uint8_t _getc(indev_t *indev)158 wchar_t _getc(indev_t *indev) 158 159 { 159 160 if (atomic_get(&haltstate)) { … … 179 180 ipl_t ipl = interrupts_disable(); 180 181 spinlock_lock(&indev->lock); 181 uint8_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN];182 wchar_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN]; 182 183 indev->counter--; 183 184 spinlock_unlock(&indev->lock); … … 193 194 * 194 195 * @param indev Input character device. 195 * @param buf Buffer where to store string terminated by '\0'.196 * @param buf Buffer where to store string terminated by NULL. 196 197 * @param buflen Size of the buffer. 197 198 * … … 201 202 count_t gets(indev_t *indev, char *buf, size_t buflen) 202 203 { 203 index_t index = 0; 204 205 while (index < buflen) { 206 char ch = _getc(indev); 204 size_t offset = 0; 205 count_t count = 0; 206 buf[offset] = 0; 207 208 wchar_t ch; 209 while ((ch = _getc(indev)) != '\n') { 207 210 if (ch == '\b') { 208 if (index > 0) { 209 index--; 210 /* Space backspace, space */ 211 if (count > 0) { 212 /* Space, backspace, space */ 211 213 putchar('\b'); 212 214 putchar(' '); 213 215 putchar('\b'); 216 217 count--; 218 offset = str_lsize(buf, count); 219 buf[offset] = 0; 214 220 } 215 continue;216 }217 putchar(ch);218 219 if (ch == '\n') { /* end of string => write 0, return */220 buf[index] = '\0';221 return (count_t) index;222 221 } 223 buf[index++] = ch; 224 } 225 226 return (count_t) index; 222 if (chr_encode(ch, buf, &offset, buflen - 1) == EOK) { 223 putchar(ch); 224 count++; 225 buf[offset] = 0; 226 } 227 } 228 229 return count; 227 230 } 228 231 229 232 /** Get character from input device & echo it to screen */ 230 uint8_t getc(indev_t *indev)231 { 232 uint8_t ch = _getc(indev);233 wchar_t getc(indev_t *indev) 234 { 235 wchar_t ch = _getc(indev); 233 236 putchar(ch); 234 237 return ch; … … 296 299 * 297 300 */ 298 unative_t sys_klog(int fd, const void * buf, size_t count)301 unative_t sys_klog(int fd, const void *buf, size_t size) 299 302 { 300 303 char *data; 301 304 int rc; 302 305 303 if ( count> PAGE_SIZE)306 if (size > PAGE_SIZE) 304 307 return ELIMIT; 305 308 306 if ( count> 0) {307 data = (char *) malloc( count+ 1, 0);309 if (size > 0) { 310 data = (char *) malloc(size + 1, 0); 308 311 if (!data) 309 312 return ENOMEM; 310 313 311 rc = copy_from_uspace(data, buf, count);314 rc = copy_from_uspace(data, buf, size); 312 315 if (rc) { 313 316 free(data); 314 317 return rc; 315 318 } 316 data[ count] = 0;319 data[size] = 0; 317 320 318 321 printf("%s", data); … … 321 324 klog_update(); 322 325 323 return count;326 return size; 324 327 } 325 328
Note:
See TracChangeset
for help on using the changeset viewer.