Changeset 8b5fb5e in mainline
- Timestamp:
- 2011-06-28T20:51:10Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4ec6820
- Parents:
- 244d6fd
- Location:
- uspace/lib/posix
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/stdint.h
r244d6fd r8b5fb5e 35 35 #ifndef POSIX_STDINT_H_ 36 36 #define POSIX_STDINT_H_ 37 38 #include "libc/stdint.h" 37 39 38 40 #undef INT8_MAX -
uspace/lib/posix/stdio.c
r244d6fd r8b5fb5e 41 41 #include "internal/common.h" 42 42 #include "stdio.h" 43 #include "libc/io/printf_core.h" 43 44 #include "string.h" 45 #include "libc/str.h" 44 46 45 47 /* not the best of solutions, but freopen will eventually … … 48 50 #include "../c/generic/private/stdio.h" 49 51 52 /** Clears the stream's error and end-of-file indicators. 53 * 54 * @param stream 55 */ 56 void posix_clearerr(FILE *stream) 57 { 58 stream->error = 0; 59 stream->eof = 0; 60 } 61 62 /** 63 * 64 * @param s 65 * @return 66 */ 67 char *posix_ctermid(char *s) 68 { 69 /* Currently always returns an error value (empty string). */ 70 // TODO: return a real terminal path 71 72 static char dummy_path[L_ctermid] = {'\0'}; 73 74 if (s == NULL) { 75 return dummy_path; 76 } 77 78 s[0] = '\0'; 79 return s; 80 } 81 50 82 /** 51 83 * … … 55 87 */ 56 88 int posix_ungetc(int c, FILE *stream) 89 { 90 // TODO 91 not_implemented(); 92 } 93 94 ssize_t posix_getdelim(char **restrict lineptr, size_t *restrict n, 95 int delimiter, FILE *restrict stream) 96 { 97 // TODO 98 not_implemented(); 99 } 100 101 ssize_t posix_getline(char **restrict lineptr, size_t *restrict n, 102 FILE *restrict stream) 57 103 { 58 104 // TODO … … 113 159 } 114 160 161 FILE *posix_fmemopen(void *restrict buf, size_t size, 162 const char *restrict mode) 163 { 164 // TODO 165 not_implemented(); 166 } 167 168 FILE *posix_open_memstream(char **bufp, size_t *sizep) 169 { 170 // TODO 171 not_implemented(); 172 } 173 115 174 /** 116 175 * … … 119 178 void posix_perror(const char *s) 120 179 { 121 // TODO 122 not_implemented(); 180 if (s == NULL || s[0] == '\0') { 181 fprintf(stderr, "%s\n", posix_strerror(errno)); 182 } else { 183 fprintf(stderr, "%s: %s\n", s, posix_strerror(errno)); 184 } 185 } 186 187 struct _posix_fpos { 188 off64_t offset; 189 }; 190 191 /** Restores stream a to position previously saved with fgetpos(). 192 * 193 * @param stream Stream to restore 194 * @param pos Position to restore 195 * @return Zero on success, non-zero (with errno set) on failure 196 */ 197 int posix_fsetpos(FILE *stream, const posix_fpos_t *pos) 198 { 199 return fseek(stream, pos->offset, SEEK_SET); 200 } 201 202 /** Saves the stream's position for later use by fsetpos(). 203 * 204 * @param stream Stream to save 205 * @param pos Place to store the position 206 * @return Zero on success, non-zero (with errno set) on failure 207 */ 208 int posix_fgetpos(FILE *restrict stream, posix_fpos_t *restrict pos) 209 { 210 off64_t ret = ftell(stream); 211 if (ret == -1) { 212 return errno; 213 } 214 pos->offset = ret; 215 return 0; 123 216 } 124 217 … … 130 223 * @return 131 224 */ 225 int posix_fseek(FILE *stream, long offset, int whence) 226 { 227 return fseek(stream, (off64_t) offset, whence); 228 } 229 230 /** 231 * 232 * @param stream 233 * @param offset 234 * @param whence 235 * @return 236 */ 132 237 int posix_fseeko(FILE *stream, posix_off_t offset, int whence) 133 238 { 134 // TODO 135 not_implemented(); 239 return fseek(stream, (off64_t) offset, whence); 240 } 241 242 /** 243 * 244 * @param stream 245 * @return 246 */ 247 long posix_ftell(FILE *stream) 248 { 249 return (long) ftell(stream); 136 250 } 137 251 … … 143 257 posix_off_t posix_ftello(FILE *stream) 144 258 { 145 // TODO 146 not_implemented(); 259 return (posix_off_t) ftell(stream); 260 } 261 262 int posix_dprintf(int fildes, const char *restrict format, ...) 263 { 264 va_list list; 265 va_start(list, format); 266 int result = posix_vdprintf(fildes, format, list); 267 va_end(list); 268 return result; 269 } 270 271 static int _dprintf_str_write(const char *str, size_t size, void *fd) 272 { 273 ssize_t wr = write(*(int *) fd, str, size); 274 return str_nlength(str, wr); 275 } 276 277 static int _dprintf_wstr_write(const wchar_t *str, size_t size, void *fd) 278 { 279 size_t offset = 0; 280 size_t chars = 0; 281 size_t sz; 282 char buf[4]; 283 284 while (offset < size) { 285 sz = 0; 286 if (chr_encode(str[chars], buf, &sz, sizeof(buf)) != EOK) { 287 break; 288 } 289 290 if (write(*(int *) fd, buf, sz) != (ssize_t) sz) { 291 break; 292 } 293 294 chars++; 295 offset += sizeof(wchar_t); 296 } 297 298 return chars; 299 } 300 301 int posix_vdprintf(int fildes, const char *restrict format, va_list ap) 302 { 303 printf_spec_t spec = { 304 .str_write = _dprintf_str_write, 305 .wstr_write = _dprintf_wstr_write, 306 .data = &fildes 307 }; 308 309 return printf_core(format, &spec, ap); 147 310 } 148 311 … … 156 319 int posix_sprintf(char *s, const char *format, ...) 157 320 { 158 // TODO 159 not_implemented(); 160 } 161 162 /** 163 * 164 * @param s 321 va_list list; 322 va_start(list, format); 323 int result = posix_vsprintf(s, format, list); 324 va_end(list); 325 return result; 326 } 327 328 /** 329 * 330 * @param s 331 * @param format 332 * @param ap 333 * @return 334 */ 335 int posix_vsprintf(char *s, const char *format, va_list ap) 336 { 337 return vsnprintf(s, STR_NO_LIMIT, format, ap); 338 } 339 340 /** 341 * 342 * @param stream 165 343 * @param format 166 344 * @param ... 167 345 * @return 168 346 */ 169 int posix_vsprintf(char *s, const char *format, va_list ap) 347 int posix_fscanf(FILE *restrict stream, const char *restrict format, ...) 348 { 349 va_list list; 350 va_start(list, format); 351 int result = posix_vfscanf(stream, format, list); 352 va_end(list); 353 return result; 354 } 355 356 int posix_vfscanf(FILE *restrict stream, const char *restrict format, va_list arg) 357 { 358 // TODO 359 not_implemented(); 360 } 361 362 /** 363 * 364 * @param format 365 * @param ... 366 * @return 367 */ 368 int posix_scanf(const char *restrict format, ...) 369 { 370 va_list list; 371 va_start(list, format); 372 int result = posix_vscanf(format, list); 373 va_end(list); 374 return result; 375 } 376 377 /** 378 * 379 * @param format 380 * @param arg 381 * @return 382 */ 383 int posix_vscanf(const char *restrict format, va_list arg) 384 { 385 return posix_vfscanf(stdin, format, arg); 386 } 387 388 /** 389 * 390 * @param s 391 * @param format 392 * @param ... 393 * @return 394 */ 395 int posix_sscanf(const char *s, const char *format, ...) 396 { 397 va_list list; 398 va_start(list, format); 399 int result = posix_vsscanf(s, format, list); 400 va_end(list); 401 return result; 402 } 403 404 /** 405 * 406 * @param s 407 * @param format 408 * @param arg 409 * @return 410 */ 411 int posix_vsscanf( 412 const char *restrict s, const char *restrict format, va_list arg) 413 { 414 // TODO 415 not_implemented(); 416 } 417 418 void posix_flockfile(FILE *file) 419 { 420 /* dummy */ 421 } 422 423 int posix_ftrylockfile(FILE *file) 424 { 425 /* dummy */ 426 return 0; 427 } 428 429 void posix_funlockfile(FILE *file) 430 { 431 /* dummy */ 432 } 433 434 int posix_getc_unlocked(FILE *stream) 435 { 436 return getc(stream); 437 } 438 439 int posix_getchar_unlocked(void) 440 { 441 return getchar(); 442 } 443 444 int posix_putc_unlocked(int c, FILE *stream) 445 { 446 return putc(c, stream); 447 } 448 449 int posix_putchar_unlocked(int c) 450 { 451 return putchar(c); 452 } 453 454 /** 455 * 456 * @param path 457 * @return 458 */ 459 int posix_remove(const char *path) 460 { 461 // FIXME: unlink() and rmdir() seem to be equivalent at the moment, 462 // but that does not have to be true forever 463 return unlink(path); 464 } 465 466 /** 467 * 468 * @param s 469 * @return 470 */ 471 char *posix_tmpnam(char *s) 170 472 { 171 473 // TODO: low priority, just a compile-time dependency of binutils … … 173 475 } 174 476 175 /**176 *177 * @param s178 * @param format179 * @param ...180 * @return181 */182 int posix_sscanf(const char *s, const char *format, ...)183 {184 // TODO185 not_implemented();186 }187 188 /**189 *190 * @param path191 * @return192 */193 int posix_remove(const char *path)194 {195 // TODO: low priority, just a compile-time dependency of binutils196 not_implemented();197 }198 199 /**200 *201 * @param s202 * @return203 */204 char *posix_tmpnam(char *s)205 {206 // TODO: low priority, just a compile-time dependency of binutils207 not_implemented();208 }209 210 477 /** @} 211 478 */ -
uspace/lib/posix/stdio.h
r244d6fd r8b5fb5e 40 40 #include "sys/types.h" 41 41 #include "libc/stdarg.h" 42 #include "limits.h" 42 43 43 /* Character Input/Output */ 44 #undef L_ctermid 45 #define L_ctermid PATH_MAX 46 47 extern void posix_clearerr(FILE *stream); 48 extern char *posix_ctermid(char *s); 49 50 /* Input/Output */ 44 51 #undef putc 45 52 #define putc fputc … … 47 54 #define getc fgetc 48 55 extern int posix_ungetc(int c, FILE *stream); 56 57 extern ssize_t posix_getdelim(char **restrict lineptr, size_t *restrict n, 58 int delimiter, FILE *restrict stream); 59 extern ssize_t posix_getline(char **restrict lineptr, size_t *restrict n, 60 FILE *restrict stream); 49 61 50 62 /* Opening Streams */ … … 54 66 FILE *restrict stream); 55 67 68 /* Memory Streams */ 69 70 extern FILE *posix_fmemopen(void *restrict buf, size_t size, 71 const char *restrict mode); 72 extern FILE *posix_open_memstream(char **bufp, size_t *sizep); 73 56 74 /* Error Messages */ 57 75 extern void posix_perror(const char *s); 58 76 59 77 /* File Positioning */ 78 79 typedef struct _posix_fpos posix_fpos_t; 80 extern int posix_fsetpos(FILE *stream, const posix_fpos_t *pos); 81 extern int posix_fgetpos(FILE *restrict stream, posix_fpos_t *restrict pos); 82 extern int posix_fseek(FILE *stream, long offset, int whence); 60 83 extern int posix_fseeko(FILE *stream, posix_off_t offset, int whence); 84 extern long posix_ftell(FILE *stream); 61 85 extern posix_off_t posix_ftello(FILE *stream); 62 86 63 87 /* Formatted Input/Output */ 64 extern int posix_sprintf(char *restrict s, const char *restrict format, ...); 88 extern int posix_dprintf(int fildes, const char *restrict format, ...) 89 PRINTF_ATTRIBUTE(2, 3); 90 extern int posix_vdprintf(int fildes, const char *restrict format, va_list ap); 91 extern int posix_sprintf(char *restrict s, const char *restrict format, ...) 92 PRINTF_ATTRIBUTE(2, 3); 65 93 extern int posix_vsprintf(char *restrict s, const char *restrict format, va_list ap); 66 extern int posix_sscanf(const char *restrict s, const char *restrict format, ...); 94 95 extern int posix_fscanf( 96 FILE *restrict stream, const char *restrict format, ...); 97 extern int posix_vfscanf( 98 FILE *restrict stream, const char *restrict format, va_list arg); 99 extern int posix_scanf(const char *restrict format, ...); 100 extern int posix_vscanf(const char *restrict format, va_list arg); 101 extern int posix_sscanf( 102 const char *restrict s, const char *restrict format, ...); 103 extern int posix_vsscanf( 104 const char *restrict s, const char *restrict format, va_list arg); 105 106 /* File Locking */ 107 108 extern void posix_flockfile(FILE *file); 109 extern int posix_ftrylockfile(FILE *file); 110 extern void posix_funlockfile(FILE *file); 111 112 extern int posix_getc_unlocked(FILE *stream); 113 extern int posix_getchar_unlocked(void); 114 extern int posix_putc_unlocked(int c, FILE *stream); 115 extern int posix_putchar_unlocked(int c); 67 116 68 117 /* Deleting Files */ … … 76 125 77 126 #ifndef LIBPOSIX_INTERNAL 127 #define clearerr posix_clearerr 128 #define ctermid posix_ctermid 129 78 130 #define ungetc posix_ungetc 131 132 #define getdelim posix_getdelim 133 #define getline posix_getline 79 134 80 135 #define freopen posix_freopen 81 136 137 #define fmemopen posix_fmemopen 138 #define open_memstream posix_open_memstream 139 82 140 #define perror posix_perror 83 141 142 #define fpos_t posix_fpos_t 143 #define fsetpos posix_fsetpos 144 #define fgetpos posix_fgetpos 145 #define fseek posix_fseek 84 146 #define fseeko posix_fseeko 147 #define ftell posix_ftell 85 148 #define ftello posix_ftello 86 149 150 #define dprintf posix_dprintf 151 #define vdprintf posix_vdprintf 87 152 #define sprintf posix_sprintf 88 153 #define vsprintf posix_vsprintf 154 155 #define fscanf posix_fscanf 156 #define vfscanf posix_vfscanf 157 #define vscanf posix_vscanf 158 #define scanf posix_scanf 89 159 #define sscanf posix_sscanf 160 #define vsscanf posix_vsscanf 161 162 #define flockfile posix_flockfile 163 #define ftrylockfile posix_ftrylockfile 164 #define funlockfile posix_funlockfile 165 166 #define getc_unlocked posix_getc_unlocked 167 #define getchar_unlocked posix_getchar_unlocked 168 #define putc_unlocked posix_putc_unlocked 169 #define putchar_unlocked posix_putchar_unlocked 90 170 91 171 #define remove posix_remove
Note:
See TracChangeset
for help on using the changeset viewer.