Changeset 63088cc1 in mainline
- Timestamp:
- 2008-12-29T13:30:19Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c1002a
- Parents:
- 04b687b
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/stdio/stdio1.c
r04b687b r63088cc1 40 40 char *file_name = "/readme"; 41 41 size_t n; 42 int c; 42 43 43 44 printf("Open file '%s'\n", file_name); … … 61 62 printf("Read string '%s'.\n", buf); 62 63 63 fclose(f); 64 printf("Seek to beginning.\n"); 65 if (fseek(f, 0, SEEK_SET) != 0) { 66 fclose(f); 67 return "Failed seeking."; 68 } 69 70 printf("Read using fgetc().\n"); 71 while (true) { 72 c = fgetc(f); 73 if (c == EOF) break; 74 75 printf("'%c'", c); 76 } 77 78 printf("[EOF]\n"); 79 printf("Closing.\n"); 80 81 if (fclose(f) != 0) 82 return "Failed closing."; 64 83 65 84 return NULL; -
uspace/lib/libc/generic/io/stdio.c
r04b687b r63088cc1 216 216 } 217 217 218 /** Read character from a stream. */ 219 int fgetc(FILE *f) 220 { 221 unsigned char c; 222 size_t n; 223 224 n = fread(&c, sizeof(c), 1, f); 225 if (n < 1) return EOF; 226 227 return (int) c; 228 } 229 230 /** Write character to a stream. */ 231 int fputc(int c, FILE *f) 232 { 233 unsigned char cc; 234 size_t n; 235 236 cc = (unsigned char) c; 237 n = fwrite(&cc, sizeof(cc), 1, f); 238 if (n < 1) return EOF; 239 240 return (int) cc; 241 } 242 243 /** Write string to a stream. */ 244 int fputs(const char *s, FILE *f) 245 { 246 int rc; 247 248 rc = 0; 249 250 while (*s && rc >= 0) { 251 rc = fputc(*s++, f); 252 } 253 254 if (rc < 0) return EOF; 255 256 return 0; 257 } 258 259 /** Seek to position in stream. */ 260 int fseek(FILE *f, long offset, int origin) 261 { 262 off_t rc; 263 264 rc = lseek(f->fd, offset, origin); 265 if (rc == (off_t) (-1)) { 266 /* errno has been set by lseek. */ 267 return -1; 268 } 269 270 f->eof = 0; 271 272 return 0; 273 } 274 218 275 /** @} 219 276 */ -
uspace/lib/libc/include/stdio.h
r04b687b r63088cc1 90 90 extern void clearerr(FILE *); 91 91 92 extern int fgetc(FILE *);; 93 extern int fputc(int, FILE *); 94 extern int fputs(const char *, FILE *); 95 96 #define getc fgetc 97 #define putc fputc 98 99 extern int fseek(FILE *, long, int); 100 101 #ifndef SEEK_SET 102 #define SEEK_SET 0 103 #define SEEK_CUR 1 104 #define SEEK_END 2 105 #endif 106 92 107 #endif 93 108 -
uspace/lib/libc/include/unistd.h
r04b687b r63088cc1 45 45 #define getpagesize() (PAGE_SIZE) 46 46 47 #define SEEK_SET 0 48 #define SEEK_CUR 1 49 #define SEEK_END 2 47 #ifndef SEEK_SET 48 #define SEEK_SET 0 49 #define SEEK_CUR 1 50 #define SEEK_END 2 51 #endif 50 52 51 53 extern ssize_t write(int, const void *, size_t);
Note:
See TracChangeset
for help on using the changeset viewer.