Update contrib.
1 /** @file ../include/stdio.h
5 /** @fn clearerr(FILE *fp)
8 Note: This description also covers the following functions -
9 feof() ferror() fileno()
11 The function clearerr clears the end-of-file and error indicators for the stream pointed
14 The function feof tests the end-of-file indicator for the stream pointed to by fp, returning non-zero if it is set.
15 The end-of-file indicator can only be cleared by the function clearerr.
17 The function ferror tests the error indicator for the stream pointed to by fp, returning non-zero if it is set.
18 The error indicator can only be reset by the clearerr function.
20 The function fileno examines the argument fp and returns its integer descriptor.
24 /* this program shows finding error set using ferror
25 * and clearing it using clearerr functions */
30 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughout the appln.
32 printf("Failed to set text-mode\n");
35 FILE* fp = fopen("c:\input.txt", "w");
36 fprintf(fp, "%s", "abcdefghijklmn");
37 fprintf(fp, "%c", '');
38 fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
40 fp=fopen("c:\input.txt","r");
43 printf("fopen failed");
48 fwrite(&a;, sizeof(char), 1, fp);
50 printf("error set in file stream");
58 printf("error cleared in file stream");
59 else printf("error still unexpected set in file stream");
69 error set in file stream
70 error cleared in file stream
81 /** @fn fclose(FILE *fp)
83 @return Upon successful completion 0 is returned.
84 Otherwise, EOF is returned and the global variable errno is set to indicate the error.
85 In either case no further access to the stream is possible.
87 The fclose function dissociates the named stream from its underlying file or set of functions. If the stream was
88 being used for output any buffered data is written first using fflush .
92 /* this program shows opening and closing of a file using fclose api */
97 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughout the appln.
99 printf("Failed to set text-mode\n");
102 fp = fopen("c:\input.txt", "w+");
105 printf("file opening failed");
109 printf("file opened successfully: Perform file operations now");
113 printf("file closed successfully");
118 printf("file closing failed");
127 file opened successfully: Perform file operations now
128 file closed successfully
135 does not handle NULL arguments; they will result in a segmentation
137 This is intentional - it makes it easier to make sure programs written
138 under are bug free. This behaviour is an implementation detail and programs should not
143 @externallyDefinedApi
146 /** @fn feof(FILE *fp)
149 Refer to clearerr() for the documentation
157 @externallyDefinedApi
160 /** @fn ferror(FILE *fp)
163 Refer to clearerr() for the documentation
169 @externallyDefinedApi
172 /** @fn fseeko(FILE *stream, off_t offset, int whence)
177 For full documentation see: http://opengroup.org/onlinepubs/007908775/xsh/fseek.html
182 @externallyDefinedApi
185 /** @fn fseeko64(FILE *stream, off64_t offset, int whence)
190 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
195 @externallyDefinedApi
198 /** @fn ftello(FILE *stream)
201 For full documentation see: http://opengroup.org/onlinepubs/007908775/xsh/fseek.html
206 @externallyDefinedApi
209 /** @fn ftello64(FILE *stream)
212 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
217 @externallyDefinedApi
220 /** @fn fflush(FILE *fp)
223 @return Upon successful completion 0 is returned.
224 Otherwise, EOF is returned and the global variable errno is set to indicate the error.
226 The function fflush forces a write of all buffered data for the given output or update fp via the stream's underlying write function.
227 The open status of the stream is unaffected.
229 If the fp argument is NULL, fflush flushes all open output streams.
233 /* this program shows flushing user space buffered data using fflush */
239 char name[20] = "c:\flush1.txt";
240 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughout the appln.
242 printf("Failed to set text-mode\n");
245 fp = fopen(name, "w+");
248 printf("Error : File open");
251 setvbuf(fp, NULL, _IOFBF, 100); // set to full buffering with NULL buffer
252 fprintf(fp, "we are trying to buffer 100 characters at once with NULL buffer.");
257 printf("fflush failed");
262 else printf("Buffer successfully flushed");
272 we are trying to buffer 100 characters at once with NULL buffer.
273 Buffer successfully flushed
284 @externallyDefinedApi
287 /** @fn fgetc(FILE *fp)
290 Note: This description also covers the following functions -
291 getc() getc_unlocked() getchar() getchar_unlocked() getw()
293 @return If successful, these routines return the next requested object
294 from the stream. Character values are returned as an unsigned char converted to an int.
295 If the stream is at end-of-file or a read error occurs,
296 the routines return EOF. The routines and ferror must be used to distinguish between end-of-file and error.
297 If an error occurs, the global variable errno is set to indicate the error.
298 The end-of-file condition is remembered, even on a terminal, and all
299 subsequent attempts to read will return EOF until the condition is cleared with
302 obtains the next input character (if present) from the stream pointed at by stream, or the next character pushed back on the stream via ungetc.
305 acts essentially identically to fgetc, but is a macro that expands in-line.
308 is equivalent to getc (stdin.);
313 from the stream pointed at by stream.
315 The getc_unlocked and getchar_unlocked functions are equivalent to getc and getchar respectively,
316 except that the caller is responsible for locking the stream
317 with flockfile before calling them.
318 These functions may be used to avoid the overhead of locking the stream
319 for each character, and to avoid input being dispersed among multiple
320 threads reading from the same stream.
324 /* this program shows reading from file using getc */
325 /* consider input.txt has the following content: */
332 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughout the appln.
334 printf("Failed to set text-mode\n");
337 fp = fopen("c:\input.txt", "w");
338 fprintf(fp, "%s", "abcdefghijklmn");
339 fprintf(fp, "%c", '\n');
340 fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
342 fp = fopen("C:\input.txt","r");
345 printf("fopen failed");
348 while((int)(retval = getc(fp) )!= EOF)
350 printf("%c", retval);
374 @externallyDefinedApi
377 /** @fn fgetpos(FILE * fp, fpos_t * pos)
380 Refer to fseek() for the documentation
387 @externallyDefinedApi
390 /** @fn fgetpos64(FILE * fp, fpos64_t * pos)
394 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
400 @externallyDefinedApi
403 /** @fn fgets(char *buf, int n, FILE *fp)
408 Note: This description also covers the following functions -
411 @return Upon successful completion fgets and gets return a pointer to the string. If end-of-file occurs before any
412 characters are read they return NULL and the buffer contents remain unchanged. If an error occurs they
413 return NULL and the buffer contents are indeterminate. The fgets and gets functions do not distinguish between end-of-file and error and
414 callers must use feof and ferror to determine which occurred.
416 The fgets function reads at most one less than the number of characters
417 specified by n from the given stream and stores them in the string buf. Reading stops when a newline character is found, at end-of-file or
418 error. The newline, if any, is retained. If any characters are read, and there is no error, a \\0 character is appended to end the string.
420 The gets function is equivalent to fgets with an infinite size and a stream of stdin,
421 except that the newline character (if any) is not stored in the string.
422 It is the caller's responsibility to ensure that the input line,if any, is sufficiently short to fit in the string.
426 /* this program shows reading characters from a file using fgets */
427 /* consider input.txt has the following content: */
429 /* fdsfdsafsdabcdefghijklmn */
435 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughout the appln.
437 printf("Failed to set text-mode\n");
440 fp = fopen("c:\input.txt", "w");
441 fprintf(fp, "%s", "abcdefghijklmn");
442 fprintf(fp, "%c", "");
443 fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
446 fp = fopen("C:\input.txt","r");
449 printf("fopen failed");
452 if(fgets(buf,18,fp) != NULL)
455 printf("Buffer is empty");
458 if(fgets(buf,2,fp) != NULL)
461 printf("Buffer is empty");
471 fdsfdsafsdabcdefghijklmn
475 Security considerations:
477 The gets function cannot be used securely.
478 Because of its lack of bounds checking,and the inability for the calling program
479 to reliably determine the length of the next incoming line,the use of this function enables malicious users
480 to arbitrarily change a running program's functionality through a buffer overflow attack.
481 It is strongly suggested that the fgets function be used in all cases.
489 @externallyDefinedApi
492 /** @fn fopen(const char *file, const char *mode)
496 Note: This description also covers the following functions -
499 @return Upon successful completion fopen, fdopen and freopen return a FILE pointer.
500 Otherwise, NULL is returned and the global variable errno is set to indicate the error.
502 Note: To open file in text-mode use set_fmode() prior to fopen() or at the start of appln. Default file opening mode in symbian is binary.
503 For more details, see set_fmode().
505 The fopen function opens the file whose name is the string pointed to by file and associates a stream with it.
507 The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):
509 "r" Open file in text mode if text-mode is set using set_fmode(), otherwise opens in default binary mode for reading. The stream is positioned at the beginning of the file.
510 "r+" Open file in text mode if text-mode is set using set_fmode(), otherwise opens in default binary mode for reading and writing. The stream is positioned at the beginning of the file.
511 "w" Truncate to zero length or create file in text mode if text-mode is set using set_fmode(), otherwise opens in default binary mode for writing. The stream is positioned at the beginning of the file.
512 "w+" Open file in text mode if text-mode is set using set_fmode(), otherwise opens in default binary mode for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
513 "a" Open file in text mode if text-mode is set using set_fmode(), otherwise opens in default binary mode for writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek or similar.
514 "a+" Open file in text mode if text-mode is set using set_fmode(), otherwise opens in default binary mode for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek or similar.
516 The mode string can also include the letter "b" either as a third character or as a character between the characters in any of the two-character strings described above while explicitly specifying binary mode.
518 The mode string can also include the letter "t" either as a third character or as a character between the characters in any of the two-character strings described above while explicitly specifying text mode.
520 Reads and writes may be intermixed on read/write streams in any order, and do not require an intermediate seek as in previous versions of stdio. This is not portable to other systems, however; ANSI C requires that a file positioning function intervene between output and input, unless an input operation encounters end-of-file.
522 The fdopen function associates a stream with the existing file descriptor, fildes. The mode of the stream must be compatible with the mode of the file descriptor. When the stream is closed via fclose, fildes is closed also.
524 The freopen function opens the file whose name is the string pointed to by path and associates the stream pointed to by stream with it. The original stream (if it exists) is closed. The mode argument is used just as in the fopen function.
526 If the file argument is NULL, freopen attempts to re-open the file associated with stream with a new mode. The new mode must be compatible with the mode that the stream was originally opened with:
528 * Streams originally opened with mode "r" can only be reopened with that same mode.
529 * Streams originally opened with mode "a" can be reopened with the same mode, or mode "w."
530 * Streams originally opened with mode "w" can be reopened with the same mode, or mode "a."
531 * Streams originally opened with mode "r+," "w+," or "a+" can be reopened with any mode.
533 The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout).
539 /* This program shows opening a file in default binary mode with write combination,write data and close */
540 /* again open in append mode and write data */
541 /* Check file c:\fopen.txt */
546 char name[20] = "c:\fopen1.txt";
548 if ((fp = fopen (name, "w")) == NULL) // Opens file in default binary mode
550 printf("Error creating file");
553 printf("Opened file");
554 fprintf(fp, "helloworld\n");
555 printf("Wrote to file");
557 printf("Closed file");
558 if ((fp = fopen (name, "a")) == NULL)
560 printf("Error opening file");
563 printf("Opened file for appending");
566 printf("closed file, check output in c:\ fopen.txt file");
578 Opened file for appending
579 closed file, check output in c:\fopen.txt file
581 Note: fopen.txt file contains:-
588 /* This program shows opening a file explicitly in text-mode using set_fmode() with write combination,write data and close */
589 /* again open in append mode and write data */
590 /* Check file c:\fopen.txt */
595 char name[20] = "c:\fopen1.txt";
596 if( set_fmode('t') != 0 )
598 printf("Failed to set text-mode\n");
601 if(get_fmode() != 't')
603 printf(" Failed to retrieve the text-mode set using set_fmode()\n");
606 if ((fp = fopen (name, "w")) == NULL) // Opens file in text-mode
608 printf("Error creating file");
611 printf("Opened file");
612 fprintf(fp, "helloworld\n");
613 printf("Wrote to file");
615 printf("Closed file");
616 if ((fp = fopen (name, "a")) == NULL)
618 printf("Error opening file");
621 printf("Opened file for appending");
624 printf("closed file, check output in c:\ fopen.txt file");
636 Opened file for appending
637 closed file, check output in c:\fopen.txt file
639 Note: fopen.txt file contains:-
648 -# Mode values for group and others are be ignored.
649 -# The execute bit and setuid on exec bit are ignored.
650 -# The default working directory of a process is initialized to C:\\private\\UID
651 (UID of the calling application) and any data written into this directory persists
652 between phone resets.
653 -# If the specified file is a symbolic link and the file it is pointing to
654 is invalid the symbolic link file will be automatically removed.
658 A file in cannot be created with write-only permission and attempting to
659 create one will result in a file with read-write permission. Creating a new file
660 with the O_CREAT flag does not alter the time stamp of its parent directory. The
661 newly created entry has only two time stamps: access and modification. Creation
662 time stamp is not supported and access time stamp is initially equal to modification
663 time stamp. open, fclose and fflush.
665 KErrNotReady of symbian error code is mapped to ENOENT, which typically means drive
666 not found or filesystem not mounted on the drive.
677 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
680 @externallyDefinedApi
683 /** @fn fopen64(const char *file, const char *mode)
688 @return Upon successful completion fopen64() return a FILE pointer.
689 Otherwise, NULL is returned and the global variable errno is set to indicate the error.
691 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
696 @externallyDefinedApi
699 /** @fn fprintf(FILE *fp, const char *fmt, ...)
704 Refer to printf() for the documentation
712 @externallyDefinedApi
715 /** @fn fputc(int c, FILE *fp)
719 Note: This description also covers the following functions -
720 putc() putc_unlocked() putchar() putchar_unlocked() putw()
722 @return The functions, fputc, putc, putchar, putc_unlocked, and putchar_unlocked return the character written.
723 If an error occurs, the value EOF is returned.
724 The putw function returns 0 on success; EOF is returned if a write error occurs,
725 or if an attempt is made to write to a read-only stream.
727 The fputc function writes the character c (converted to an "unsigned char")
728 to the output stream pointed to by fp.
730 The putc macro that is identically to fputc, but is a macro that expands in-line.
731 It may evaluate stream more than once, so arguments given to putc should not be expressions with potential side effects.
733 The putchar function is identical to putc with an output stream of stdout.
735 The putw function writes the specified int to the named output stream.
737 The putc_unlocked and putchar_unlocked functions are equivalent to putc and putchar respectively,
738 except that the caller is responsible for locking the stream with flockfile before calling them.
739 These functions may be used to avoid the overhead of locking the stream for each character,
740 and to avoid output being interspersed from multiple threads writing to the same stream.
749 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughout the appln.
751 printf("Failed to set text-mode\n");
754 fp=fopen("C:\input.txt","w+");
758 printf("file opening failed");
761 if(putc('a',fp)!='a')
763 printf("putc failed");
767 else printf("character successfully put by putc");
777 character successfully put by putc
788 @externallyDefinedApi
791 /** @fn fputs(const char *s, FILE *fp)
795 Note: This description also covers the following functions -
798 @return The fputs function returns 0 on success and EOF on error. The puts function returns a nonnegative integer on success and EOF on error.
800 The function fputs writes the string pointed to by s to the stream pointed to by fp.
802 The function puts writes the string s, and a terminating newline character,
803 to the stream stdout.
808 /*this program shows writing characters from a file using fputs */
809 /* consider input.txt has the following content: */
815 char rs1[50],rs2[50];
819 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughout the appln.
821 printf("Failed to set text-mode\n");
824 fp = fopen("c:\input.txt", "w");
825 fprintf(fp, "%s", "abcdefghijklmn");
826 fprintf(fp, "%c", "");
827 fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
829 fp = fopen("c:\input.txt","r");
832 printf("fopen failed");
835 rptr = fgets(rs1,12,fp);
838 printf("fgets failed");
843 fp = fopen("c:\puts1.txt","w+");
846 printf("fopen failed");
849 wretval = fputs(rs1,fp);
852 printf("fputs failed");
857 fp = fopen("C:\puts1.txt","r");
860 printf("fopen failed");
863 rptr = fgets(rs2,12,fp);
866 printf("fgets failed");
870 printf("file reading returned \"%s\",rs2);
872 unlink("C:\puts1.txt");
881 file reading returned "abcdefghijk"
890 @externallyDefinedApi
893 /** @fn fread(void * buf, size_t size, size_t count, FILE * fp)
899 Note: This description also covers the following functions -
902 @return The functions fread and fwrite advance the file position indicator for the stream
903 by the number of bytes read or written.
904 They return the number of objects read or written.
905 If an error occurs, or the end-of-file is reached,
906 the return value is a short object count (or zero). The function fread does not distinguish between end-of-file and error. Callers
907 must use feof and ferror to determine which occurred. The function fwrite returns a value less than count only if a write error has occurred.
909 The function fread reads count objects, each size bytes long, from the stream pointed to by fp, storing them at the location given by buf.
911 The function fwrite writes count objects, each size bytes long, to the stream pointed to by fp, obtaining them from the location given by buf.
916 /* this program shows reading characters from a file using fread */
917 /* consider input.txt has the following content: */
924 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
926 printf("Failed to set text-mode\n");
929 fp = fopen("c:\input.txt", "w");
930 fprintf(fp, "%s", "abcdefghijklmn");
931 fprintf(fp, "%c", '\n');
932 fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
934 fp = fopen("c:\input.txt", "r");
937 printf ("fopen failed");
940 // read single chars at a time, stopping on EOF or error:
941 while (fread(&a;, sizeof(char), 1, fp), !feof(fp) && !ferror(fp))
943 printf("I read \"%c\",a);
945 if (ferror(fp)) //Some error occurred
967 @externallyDefinedApi
970 /** @fn freopen(const char *file, const char *mode, FILE *fp)
975 Refer to fopen() for the documentation
983 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
986 @externallyDefinedApi
989 /** @fn freopen64(const char *file, const char *mode, FILE *fp)
994 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
999 @externallyDefinedApi
1002 /** @fn fscanf(FILE * fp, const char * fmt, ...)
1007 Refer to scanf() for the documentation
1018 @externallyDefinedApi
1021 /** @fn fseek(FILE *fp, long offset, int whence)
1026 Note: This description also covers the following functions -
1027 ftell() rewind() fgetpos() fsetpos()
1029 @return The rewind function returns no value.
1030 Upon successful completion ftell returns the current offset. Otherwise -1 is returned and the global variable errno is set to indicate the error.
1032 The fseek function sets the file position indicator for the stream pointed to by fp.
1033 The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence.
1034 If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the file,
1035 the current position indicator, or end-of-file, respectively.
1036 A successful call to the fseek function clears the end-of-file indicator for the stream and
1037 undoes any effects of the ungetc and ungetwc functions on the same stream.
1038 The fseek function call does not allows the file offset to be set beyond the end of the existing end-of-file of the file.
1040 The ftell function obtains the current value of the file position indicator for the stream pointed to by fp.
1042 The rewind function sets the file position indicator for the stream pointed to by fp to the beginning of the file. It is equivalent to:
1045 (void)fseek(fp, 0L, SEEK_SET)
1049 except that the error indicator for the stream is also cleared.
1050 Since rewind does not return a value, an application wishing to detect errors should clear errno,
1051 then call rewind, and if errno is non-zero, assume an error has occurred.
1052 The fgetpos and fsetpos functions are alternate interfaces for retrieving and setting the current position
1053 in the file, similar to ftell and fseek, except that the current position is stored in an opaque object of
1054 type fpos_t pointed to by pos. These functions provide a portable way to seek to offsets larger than those that
1055 can be represented by a long int. They may also store additional state information in the fpos_t object to
1056 facilitate seeking within files containing multibyte characters with state-dependent encodings.
1057 Although fpos_t has traditionally been an integral type, applications cannot assume that it is;
1058 in particular, they must not perform arithmetic on objects of this type.
1059 If the stream is a wide character stream, the position specified by the combination of offset and whence must
1060 contain the first byte of a multibyte sequence.
1062 Notes: Specific to text-mode Support:
1063 1. To open file in text-mode use set_fmode() prior to fopen() or at the start of appln. Default file opening mode in symbian is binary.
1064 For more details, see set_fmode().
1065 2. Offset set using fseek() in text-mode will not be appropriate because every newline will be converted to symbian specific
1066 line-encodings( \n --> \r\n), thereby returning inappropriate offset values.
1067 Thus, fseek(), ftell() will not return values as expected by the User.
1068 3. Offset value returned from ftell() can be used to pass to fseek() and
1069 will not affect the functionality of any next read, write operations.
1074 /* this program shows setting file offset using fseek */
1080 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
1082 printf("Failed to set text-mode\n");
1085 fp = fopen("c:\input.txt", "w"); // opens file in default binary mode, hence fseek() works fine.
1086 fprintf(fp, "%s", "abcdefghijklmn");
1087 fprintf(fp, "%c", '');
1088 fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
1090 fp = fopen("c:\input.txt", "r");
1093 printf ("fopen failed");
1096 retval = fseek(fp, 3, SEEK_SET); // seek to the 20th byte of the file
1099 printf ("fseek failed");
1103 long pos = ftell(fp);
1106 printf("offset setting proper");
1116 offset setting proper
1130 @externallyDefinedApi
1133 /** @fn fsetpos(FILE *iop, const fpos_t *pos)
1137 Refer to fseek() for the documentation
1144 @externallyDefinedApi
1147 /** @fn fsetpos64(FILE *iop, const fpos64_t *pos)
1151 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
1157 @externallyDefinedApi
1160 /** @fn ftell(FILE *fp)
1163 Refer to fseek(), set_fmode() for the documentation
1171 @externallyDefinedApi
1174 /** @fn fwrite(const void * buf, size_t size, size_t count, FILE * fp)
1180 Refer to fread() for the documentation
1186 @externallyDefinedApi
1189 /** @fn getc(FILE *fp)
1192 Refer to fgetc() for the documentation
1203 @externallyDefinedApi
1209 Refer to fgetc() for the documentation
1220 @externallyDefinedApi
1223 /** @fn gets(char *str)
1226 Refer to fgets() for the documentation
1233 @externallyDefinedApi
1236 /** @fn perror(const char *string)
1239 Note: This description also covers the following functions -
1240 strerror() strerror_r()
1242 @return strerror function returns the appropriate error description string,
1243 or an unknown error message if the error code is unknown. The value of errno
1244 is not changed for a successful call and is set to a nonzero value upon error.
1245 The strerror_r function returns 0 on success and -1 on failure, setting
1248 The strerror , strerror_r and perror functions look up the error message string corresponding to an
1251 The strerror function accepts an error number argument errnum and returns a pointer to the corresponding
1254 The strerror_r function renders the same result into strerrbuf for a maximum of buflen characters and returns 0 upon success.
1256 The perror function finds the error message corresponding to the current
1257 value of the global variable errno and writes it, followed by a newline, to the
1258 standard error file descriptor.
1259 If the argument string is non- NULL and does not point to the null character,
1260 this string is prepended to the message
1261 string and separated from it by
1262 a colon and space (": ");
1263 otherwise, only the error message string is printed.
1265 If the error number is not recognized, these functions return an error message
1266 string containing "Unknown error: "
1267 followed by the error number in decimal.
1268 The strerror and strerror_r functions return EINVAL as a warning.
1269 Error numbers recognized by this implementation fall in
1270 the range 0 \< errnum \< sys_nerr .
1272 If insufficient storage is provided in strerrbuf (as specified in buflen )
1273 to contain the error string, strerror_r returns ERANGE and strerrbuf will contain an error message that has been truncated and NUL terminated to fit the length specified by buflen .
1275 The message strings can be accessed directly using the external
1277 The external value sys_nerr contains a count of the messages in sys_errlist .
1278 The use of these variables is deprecated; strerror or strerror_r should be used instead.
1287 char *ptr = strerror(ERANGE);
1288 printf("strerror(ERANGE) = %s",ptr);
1296 strerror(ERANGE) = Numerical result out of range
1304 For unknown error numbers, the strerror function will return its result in a static buffer which
1305 may be overwritten by subsequent calls. The return type for strerror is missing a type-qualifier; it should actually be const char * . Programs that use the deprecated sys_errlist variable often fail to compile because they declare it
1310 @externallyDefinedApi
1313 /** @fn printf(const char *fmt, ...)
1317 Note: This description also covers the following functions -
1318 fprintf() sprintf() snprintf() asprintf() vprintf() vfprintf() vsprintf() vsnprintf() vasprintf()
1320 @return Upon successful return, these functions return the number of characters printed (not including the trailing \\0 used to end output to strings).
1321 The functions snprintf and vsnprintf do not write more than size bytes (including the trailing \\0).
1322 If the output was truncated due to this limit then the return value
1323 is the number of characters (not including the trailing \\0)
1324 which would have been written to the final string if enough
1325 space had been available. Thus, a return value of size or more
1326 means that the output was truncated.
1327 If an output error is encountered, a negative value is returned.
1329 The printf family of functions produces output according to a format as described below. The printf and vprintf functions write output to stdout, the standard output stream; fprintf and vfprintf write output to the given output stream; sprintf, snprintf, vsprintf, and vsnprintf write to the character string str; and asprintf and vasprintf dynamically allocate a new string with malloc.
1331 These functions write the output under the control of a format string that specifies how subsequent arguments (or arguments accessed via the variable-length argument facilities of stdarg ) are converted for output.
1333 These functions return the number of characters printed (not including the trailing '\\0' used to end output to strings) or a negative value if an output error occurs, except for snprintf and vsnprintf, which return the number of characters that would have been printed if the size were unlimited (again, not including the final '\\0').
1335 The asprintf and vasprintf functions set *ret to be a pointer to a buffer sufficiently large to hold the formatted string. This pointer should be passed to free to release the allocated storage when it is no longer needed. If sufficient space cannot be allocated, asprintf and vasprintf will return -1 and set ret to be a NULL pointer.
1337 The snprintf and vsnprintf functions will write at most size -1 of the characters printed into the output string (the size'th character then gets the terminating '\\0' );if the return value is greater than or equal to the size argument, the string was too short and some of the printed characters were discarded. The output is always null-terminated.
1339 The sprintf and vsprintf functions effectively assume an infinite size.
1342 The format string is composed of zero or more directives: ordinary characters (not % ), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the % character. The arguments must correspond properly (after type promotion) with the conversion specifier. After the %, the following appear in sequence:
1344 * An optional field, consisting of a decimal digit string followed by a $, specifying the next argument to access. If this field is not provided, the argument following the last argument accessed will be used. Arguments are numbered starting at 1. If unaccessed arguments in the format string are interspersed with ones that are accessed the results will be indeterminate.
1345 * Zero or more of the following flags:
1346 '#' The value should be converted to an "alternate form." For c, d, i, n, p, s, and u conversions, this option has no effect. For o conversions, the precision of the number is increased to force the first character of the output string to a zero (except if a zero value is printed with an explicit precision of zero). For x and X conversions, a non-zero result has the string '0x' (or '0X' for X conversions) prepended to it. For a, A, e, E, f, F, g, and G conversions, the result will always contain a decimal point, even if no digits follow it (normally, a decimal point appears in the results of those conversions only if a digit follows). For g and G conversions, trailing zeros are not removed from the result as they would otherwise be.
1347 '0(zero)' Zero padding. For all conversions except n, the converted value is padded on the left with zeros rather than blanks. If a precision is given with a numeric conversion (d, i, o, u, i, x, and X), the 0 flag is ignored.
1348 '-' A negative field width flag; the converted value is to be left adjusted on the field boundary. Except for n conversions, the converted value is padded on the right with blanks, rather than on the left with blanks or zeros. A - overrides a 0 if both are given.
1349 ' (space)' A blank should be left before a positive number produced by a signed conversion (a, A, d, e, E, f, F, g, G, or i).
1350 '+' A sign must always be placed before a number produced by a signed conversion. A + overrides a space if both are used.
1351 ''' Decimal conversions (d, u, or i) or the integral portion of a floating point conversion (f or F) should be grouped and separated by thousands using the non-monetary separator returned by localeconv.
1352 * An optional decimal digit string specifying a minimum field width. If the converted value has fewer characters than the field width, it will be padded with spaces on the left (or right, if the left-adjustment flag has been given) to fill out the field width.
1353 * An optional precision, in the form of a period . followed by an optional digit string. If the digit string is omitted, the precision is taken as zero. This gives the minimum number of digits to appear for d, i, o, u, x, and X conversions, the number of digits to appear after the decimal-point for a, A, e, E, f, and F conversions, the maximum number of significant digits for g and G conversions, or the maximum number of characters to be printed from a string for s conversions.
1354 * An optional length modifier, that specifies the size of the argument. The following length modifiers are valid for the d, i, n, o, u, x, or X conversion:
1356 Modifier d, i o, u, x, X n
1357 hh signed char unsigned char signed char *
1358 h short unsigned short short *
1359 l (ell) long unsigned long long *
1360 ll (ell ell) long long unsigned long long long long *
1361 j intmax_t uintmax_t intmax_t *
1362 t ptrdiff_t (see note) ptrdiff_t *
1363 z (see note) size_t (see note)
1364 q (deprecated) quad_t u_quad_t quad_t *
1367 Note: the t modifier, when applied to a o, u, x, or X conversion, indicates that the argument is of an unsigned type equivalent in size to a ptrdiff_t. The z modifier, when applied to a d or i conversion, indicates that the argument is of a signed type equivalent in size to a size_t. Similarly, when applied to an n conversion, it indicates that the argument is a pointer to a signed type equivalent in size to a size_t.
1369 The following length modifier is valid for the a, A, e, E, f, F, g, or G conversion:
1371 Modifier a, A, e, E, f, F, g, G
1372 l (ell) double (ignored, same behavior as without it)
1376 The following length modifier is valid for the c or s conversion:
1379 l (ell) wint_t wchar_t *
1382 * A character that specifies the type of conversion to be applied.
1384 A field width or precision, or both, may be indicated by an asterisk '*' or an asterisk followed by one or more decimal digits and a '\$' instead of a digit string. In this case, an int argument supplies the field width or precision. A negative field width is treated as a left adjustment flag followed by a positive field width; a negative precision is treated as though it were missing. If a single format directive mixes positional (nn$) and non-positional arguments, the results are undefined.
1387 The conversion specifiers and their meanings are:
1389 The int (or appropriate variant) argument is converted to signed decimal (d and i), unsigned octal (o,) unsigned decimal (u,) or unsigned hexadecimal (x and X) notation. The letters "abcdef" are used for x conversions; the letters "ABCDEF" are used for X conversions. The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded on the left with zeros.
1390 DOU The long int argument is converted to signed decimal, unsigned octal, or unsigned decimal, as if the format had been ld, lo, or lu respectively. These conversion characters are deprecated, and will eventually disappear.
1391 eE The double argument is rounded and converted in the style [-d . ddd e \*[Pm] dd] where there is one digit before the decimal-point character and the number of digits after it is equal to the precision; if the precision is missing, it is taken as 6; if the precision is zero, no decimal-point character appears. An E conversion uses the letter 'E' (rather than 'e') to introduce the exponent. The exponent always contains at least two digits; if the value is zero, the exponent is 00.
1393 For a, A, e, E, f, F, g, and G conversions, positive and negative infinity are represented as inf and -inf respectively when using the lowercase conversion character, and INF and -INF respectively when using the uppercase conversion character. Similarly, NaN is represented as nan when using the lowercase conversion, and NAN when using the uppercase conversion.
1394 fF The double argument is rounded and converted to decimal notation in the style [-ddd . ddd,] where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal point appears, at least one digit appears before it.
1395 gG The double argument is converted in style f or e (or F or E for G conversions). The precision specifies the number of significant digits. If the precision is missing, 6 digits are given; if the precision is zero, it is treated as 1. Style e is used if the exponent from its conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit.
1396 aA The double argument is rounded and converted to hexadecimal notation in the style [-0x h . hhhp[\*[Pm]d,]] where the number of digits after the hexadecimal-point character is equal to the precision specification. If the precision is missing, it is taken as enough to represent the floating-point number exactly, and no rounding occurs. If the precision is zero, no hexadecimal-point character appears. The p is a literal character 'p' and the exponent consists of a positive or negative sign followed by a decimal number representing an exponent of 2. The A conversion uses the prefix "0X" (rather than "0x"), the letters "ABCDEF" (rather than "abcdef)" to represent the hex digits, and the letter 'P' (rather than 'p') to separate the mantissa and exponent.
1398 Note that there may be multiple valid ways to represent floating-point numbers in this hexadecimal format. For example, 0x3.24p+0, 0x6.48p-1 and 0xc.9p-2 are all equivalent. The format chosen depends on the internal representation of the number, but the implementation guarantees that the length of the mantissa will be minimized. Zeroes are always represented with a mantissa of 0 (preceded by a '-' if appropriate) and an exponent of +0.
1399 C Treated as c with the l (ell) modifier.
1400 c The int argument is converted to an unsigned char , and the resulting character is written.
1402 If the l (ell) modifier is used, the wint_t argument shall be converted to a wchar_t, and the (potentially multi-byte) sequence representing the single wide character is written, including any shift sequences. If a shift sequence is used, the shift state is also restored to the original state after the character.
1403 S Treated as s with the l (ell) modifier.
1404 s The char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a terminating NUL character; if a precision is specified, no more than the number specified are written. If a precision is given, no null character need be present; if the precision is not specified, or is greater than the size of the array, the array must contain a terminating NUL character.
1406 If the l (ell) modifier is used, the wchar_t * argument is expected to be a pointer to an array of wide characters (pointer to a wide string). For each wide character in the string, the (potentially multi-byte) sequence representing the wide character is written, including any shift sequences. If any shift sequence is used, the shift state is also restored to the original state after the string. Wide characters from the array are written up to (but not including) a terminating wide NUL character; if a precision is specified, no more than the number of bytes specified are written (including shift sequences). Partial characters are never written. If a precision is given, no null character need be present; if the precision is not specified, or is greater than the number of bytes required to render the multibyte representation of the string, the array must contain a terminating wide NUL character.
1407 p The void * pointer argument is printed in hexadecimal (as if by '%#x' or '%#lx' ).
1408 n The number of characters written so far is stored into the integer indicated by the int * (or variant) pointer argument. No argument is converted.
1409 % A '%' is written. No argument is converted. The complete conversion specification is '%%'.
1413 The decimal point character is defined in the program's locale (category LC_NUMERIC ).
1415 In no case does a non-existent or small field width cause truncation of a numeric field; if the result of a conversion is wider than the field width, the field is expanded to contain the conversion result.
1421 To print a date and time in the form "Sunday, July 3, 10:02",
1422 where weekday and month are pointers to strings:
1425 fprintf(stdout, "%s, %s %d, %.2d:%.2d
1427 weekday, month, day, hour, min);
1431 to five decimal places:
1435 fprintf(stdout, "pi = %.5f
1439 To allocate a 128 byte string and print into it:
1444 char *newfmt(const char *fmt, ...)
1448 if ((p = malloc(128)) == NULL)
1451 (void) vsnprintf(p, 128, fmt, ap);
1458 /* this program shows printing onto the console using printf */
1462 char * msg="hello world";
1475 /* this program shows reading from console using scanf */
1480 printf("enter message to be printed");
1482 printf("message entered is: %s",msg);
1490 enter message to be printed
1491 hello (assuming this is user input)
1492 message entered is: hello
1496 Security considerations:
1498 The sprintf and vsprintf functions are easily misused in a manner which enables malicious users
1499 to arbitrarily change a running program's functionality through
1500 a buffer overflow attack.
1501 Because sprintf and vsprintf assume an infinitely long string,
1502 callers must be careful not to overflow the actual space;
1503 this is often hard to assure.
1504 For safety, programmers should use the snprintf interface instead.
1506 The printf and sprintf family of functions are also easily misused in a manner
1507 allowing malicious users to arbitrarily change a running program's
1508 functionality by either causing the program
1509 to print potentially sensitive data "left on the stack",
1510 or causing it to generate a memory fault or bus error
1511 by dereferencing an invalid pointer. \%n can be used to write arbitrary data to potentially carefully-selected
1513 Programmers are therefore strongly advised to never pass untrusted strings
1514 as the format argument, as an attacker can put format specifiers in the string
1515 to mangle your stack,
1516 leading to a possible security hole.
1517 This holds true even if the string was built using a function like snprintf, as the resulting string may still contain user-supplied conversion specifiers
1518 for later interpolation by printf. Always use the proper secure idiom:
1521 snprintf(buffer, sizeof(buffer), "%s", string);
1523 @return None of these functions support long double length modifiers. Floating point
1524 format specifiers support a maximum precision of 15 digits.
1534 The conversion formats \%D, \%O, and \%U are not standard and
1535 are provided only for backward compatibility.
1536 The effect of padding the \%p format with zeros (either by the 0 flag or by specifying a precision), and the benign effect (i.e., none)
1537 of the \# flag on \%n and \%p conversions, as well as other
1538 nonsensical combinations such as \%Ld, are not standard; such combinations
1539 should be avoided. The printf family of functions do not correctly handle multibyte characters in the format argument.
1543 @externallyDefinedApi
1546 /** @fn putc(int c, FILE *fp)
1550 Refer to fputc() for the documentation
1559 @externallyDefinedApi
1562 /** @fn putchar(int c)
1565 Refer to fputc() for the documentation
1574 @externallyDefinedApi
1577 /** @fn puts(const char *str)
1580 Refer to fputs() for the documentation
1587 @externallyDefinedApi
1590 /** @fn remove(const char *file)
1592 @return Upon successful completion, reomve return 0.
1593 Otherwise, -1 is returned and the global variable errno is set to indicate the error.
1595 The remove function removes the file or directory specified by file.
1597 If file specifies a directory, remove (file); is the equivalent of rmdir (file); Otherwise, it is the equivalent of unlink (file);
1602 /* this program shows deleting a file using remove */
1606 char *name = "C:\input.txt";
1608 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
1610 printf("Failed to set text-mode\n");
1613 fp = fopen(name, "w+");
1616 printf ("fopen failed");
1619 fprintf(fp,"hello world");
1626 printf ("file has been deleted already");
1630 printf("remove failed");
1641 file has been deleted already
1647 - The file parameter of the remove() function should not exceed 256 characters in length.
1648 - P.I.P.S. only simulates link files and does not distinguish between hard and symbolic links.
1649 - KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive
1650 not found or filesystem not mounted on the drive.
1657 @capability Deferred @ref RFs::RmDir(const TDesC16&)
1660 @externallyDefinedApi
1663 /** @fn rename(const char *oldpath, const char *newpath)
1666 @return The rename() function returns the value 0 if successful; otherwise the
1667 value -1 is returned and the global variable errno is set to indicate the
1670 The rename system call
1671 causes the link named oldpath to be renamed as to. If to exists, it is first removed.
1672 Both oldpath and newpath must be of the same type (that is, both directories or both
1673 non-directories), and must reside on the same file system.
1675 If the final component of oldpath is a symbolic link,
1676 the symbolic link is renamed,
1677 not the file or directory to which it points.
1679 If a file with a symbolic link pointing to it is renamed, then
1680 a subsequent open call on the symbolic link file would automatically remove the link file, i.e
1681 consider a symbolic file link.x pointing to a file abc.x. If the file abc.x is
1682 renamed to abcd.x then, a subsequent open call on link.x file would automatically remove link.x file.
1685 -# rename() does not differentiate between hard and soft links.
1686 -# If the specified file is a dangling link file, then this link file will be automatically removed.
1692 - The to and from parameters in rename() shouldn't exceed 256 characters.
1693 - The rename() function fails if either from or to parameters refer to a file in use (that is, if either file is held open by a process).
1694 - The parent directory time stamps are not affected when rename() creates a new entry. The time stamps for the new entry like time of last access
1695 is equal to time of last data modification. The time of last file status change for any file would be 0.
1696 - KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive
1697 not found or filesystem not mounted on the drive.
1702 * Detailed description: This sample code demonstrates usage of rename system call.
1704 * Preconditions: Example.cfg file should be present in the current working directory.
1709 if(rename("Example.txt" , "Example2.txt") < 0 ) {
1710 printf("Failed to rename Example.txt");
1713 printf("Rename successful");
1727 @capability Deferred @ref RFs::Rename(const TDesC16&, const TDesC16&)
1728 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
1729 @capability Deferred @ref RFs::RmDir(const TDesC16&)
1730 @capability Deferred @ref RFs::SetAtt(const TDesC16&, unsigned, unsigned)
1731 @capability Deferred @ref RFs::Delete(const TDesC16&)
1734 @externallyDefinedApi
1737 /** @fn rewind(FILE *fp)
1740 Refer to fseek() for the documentation
1747 @externallyDefinedApi
1750 /** @fn scanf(const char * fmt, ...)
1754 Note: This description also covers the following functions -
1755 fscanf() sscanf() vscanf() vsscanf() vfscanf()
1757 @return These functions return the number of input items assigned, which
1758 can be fewer than provided for, or even zero, in the event of a matching failure.
1759 Zero indicates that, while there was input available, no conversions were assigned;
1760 typically this is due to an invalid input character, such as an alphabetic character
1761 for a '\%d' conversion. The value EOF is returned if an input failure occurs before any conversion such
1762 as an end-of-file occurs. If an error or end-of-file occurs after conversion has
1763 begun, the number of conversions which were successfully completed is returned.
1767 The scanf family of functions scans input according to a format as described below. This format may contain conversion specifiers; the results from such conversions, if any, are
1768 stored through the pointer arguments. The scanf function reads input from the standard input stream stdin, fscanf reads input from the stream pointer stream, and sscanf reads its input from the character string pointed to by str. The vfscanf function is analogous to vfprintf and reads input from the stream pointer stream using a variable argument list of pointers (see stdarg).
1770 The vscanf function scans a variable argument list from the standard input
1771 and the vsscanf function scans it from a string; these are analogous to the vprintf and vsprintf functions respectively. Each successive pointer argument must correspond properly with each successive conversion
1772 specifier (but see the * conversion below). All conversions are introduced by the \% (percent sign) character. The format string may also contain other characters. White space (such as
1773 blanks, tabs, or newlines) in the format string match any amount of white space, including none, in the
1774 input. Everything else matches only itself. Scanning stops when an input character
1775 does not match such a format character. Scanning also stops when an input conversion
1776 cannot be made (see below).
1781 /* this program shows scanning from file using fscanf */
1787 char* filename="c:\ScanfTest1.txt";
1789 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
1791 printf("Failed to set text-mode\n");
1794 fp=fopen(filename,"w");
1795 fprintf(fp,"%s","abcdesdafg");
1797 fp=fopen(filename,"r");
1798 ret=fscanf(fp,"%c",&x;);
1800 printf("fscanf returned:%c",x);
1819 /* this program shows scanning from file using fscanf */
1825 char* filename="c:\ScanfTest1.txt";
1827 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
1829 printf("Failed to set text-mode\n");
1832 fp=fopen(filename,"w");
1833 fprintf(fp,"%s","abcdesdafg");
1835 fp=fopen(filename,"r");
1836 ret=fscanf(fp,"%c",&x;);
1838 printf("fscanf returned:%c",x);
1855 @return None of these functions support long double data types.
1867 @externallyDefinedApi
1870 /** @fn setbuf(FILE * fp, char * buf)
1874 Note: This description also covers the following functions -
1875 setbuffer() setlinebuf() setvbuf()
1877 The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a newline is output or input is read from any stream attached to a terminal device (typically stdin). The function fflush may be used to force the block out early.
1879 Normally all files are block buffered. When the first I/O operation occurs on a file, malloc is called, and an optimally-sized buffer is obtained. If a stream refers to a terminal (as stdout normally does) it is line buffered. The standard error stream stderr is always unbuffered.
1881 The setvbuf function may be used to alter the buffering behavior of a stream. The mode argument must be one of the following three macros:
1892 The size argument may be given as zero to obtain deferred optimal-size buffer allocation as usual. If it is not zero, then except for unbuffered files, the buf argument should point to a buffer at least size bytes long; this buffer will be used instead of the current buffer. If buf is not NULL, it is the caller's responsibility to free this buffer after closing the stream.
1894 The setvbuf function may be used at any time, but may have peculiar side effects (such as discarding input or flushing output) if the stream is "active". Portable applications should call it only once on any given stream, and before any I/O is performed.
1896 The other three calls are, in effect, simply aliases for calls to setvbuf. Except for the lack of a return value, the setbuf function is exactly equivalent to the call
1899 setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
1902 The setbuffer function is the same, except that the size of the buffer is up to the caller, rather than being determined by the default BUFSIZ. The setlinebuf function is exactly equivalent to the call:
1904 setvbuf(stream, (char *)NULL, _IOLBF, 0);
1910 /* this program shows setting up a buffer using setbuf * /
1918 char name[20] = "c:\setbuf1.txt";
1919 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
1921 printf("Failed to set text-mode\n");
1924 fp = fopen(name, "w+");
1927 printf ("fopen failed");
1930 setbuf(fp, FullBuf); // Fully buffered
1933 printf ("setbuf failed");
1938 fprintf(fp, "we are trying to buffer 20 characters at once ");
1942 rptr = fgets(msg,100,fp);
1945 printf("fgets failed");
1949 printf("file reading returned \"%s\",msg);
1960 file reading returned "we are trying to buffer 20 characters at once"
1971 @externallyDefinedApi
1974 /** @fn setvbuf(FILE * fp, char * buf, int mode, size_t size)
1980 Refer to setbuf() for the documentation
1988 @externallyDefinedApi
1991 /** @fn sprintf(char * str, const char * fmt, ...)
1996 Refer to printf() for the documentation
2004 @externallyDefinedApi
2007 /** @fn sscanf(const char * str, const char * fmt, ...)
2012 Refer to scanf() for the documentation
2023 @externallyDefinedApi
2026 /** @fn tmpfile(void)
2029 Note: This description also covers the following functions -
2032 @return The tmpfile function
2033 returns a pointer to an open file stream on success, and a NULL pointer
2034 on error. The tmpnam and tempfile functions
2035 return a pointer to a file name on success, and a NULL pointer
2038 The tmpfile function
2039 returns a pointer to a stream associated with a file descriptor returned
2040 by the routine mkstemp .
2041 The created file is unlinked before tmpfile returns, causing the file to be automatically deleted when the last
2042 reference to it is closed.
2043 The file is opened with the access value 'w+'.
2044 The file is created in the directory determined by the environment variable TMPDIR if set.
2045 The default location if TMPDIR is not set is /tmp .
2048 The tmpnam function returns a pointer to a file name, in the P_tmpdir directory, which did not reference an existing file at some
2049 indeterminate point in the past. P_tmpdir is defined in the include file #include <stdio.h>. If the argument str is non- NULL , the file name is copied to the buffer it references. Otherwise,
2050 the file name is copied to a static buffer. In either case, tmpnam returns a pointer to the file name.
2052 The buffer referenced by str is expected to be at least L_tmpnam bytes in length. L_tmpnam is defined in the include file \#include \<stdio.h\>.
2054 The tempnam function
2055 is similar to tmpnam ,
2056 but provides the ability to specify the directory which will
2057 contain the temporary file and the file name prefix.
2059 The environment variable TMPDIR (if set), the argument tmpdir (if non- NULL ),
2060 the directory P_tmpdir ,
2061 and the directory /tmp are tried, in the listed order, as directories in which to store the
2064 The argument prefix , if non- NULL , is used to specify a file name prefix, which will be the
2065 first part of the created file name. The tempnam function allocates memory in which to store the file name;
2066 the returned pointer may be used as a subsequent argument to free .
2070 #include<stdio.h> //SEEK_SET, printf, tmpfile, FILE
2071 #include<sys/stat.h> //S_IWUSR
2075 //create the tmp directory
2076 mkdir("c:\tmp", S_IWUSR);
2078 //call tmpfile to create a tempory file
2079 FILE* fp = tmpfile();
2084 //write onto the file
2085 fprintf(fp, "%s", "hello");
2088 //seek to the beginning of the file
2089 fseek(fp, SEEK_SET, 0); //beg of the file
2091 //read from the file
2092 fscanf(fp, "%s", buf);
2099 printf("buf read: %s", buf);
2112 #include<stdio.h> //tmpnam, printf, FILE
2113 #include<sys/stat.h> //S_IWUSR
2114 #include<errno.h> //errno
2118 //create a directory c:\system emp
2119 mkdir("c:\system\temp", S_IWUSR);
2124 //call tmpnam() to create a file
2125 char *rval = tmpnam(buf);
2128 //open the file with the name returned by tmpnam()
2129 FILE *fp = fopen(buf, "w");
2133 printf("fopen of file returned by tmpnam() failed - errno %d ", errno);
2139 fprintf(fp, "%s", "check");
2143 fp = fopen(buf, "r");
2147 fscanf(fp, "%s", rbuf);
2151 printf("read from file: %s", rbuf);
2152 printf("argument buf: %s", buf);
2153 printf("return value: %s", rval);
2162 read from file: check
2163 argument buf: /System/temp/tmp.0.U9UPTx
2164 return value: /System/temp/tmp.0.U9UPTx
2170 - The str parameter in tmpnam() respectively should not exceed 256 characters in length.
2171 - The tmpdir parameter in tempnam() respectively should not exceed 256 characters in length.
2177 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
2180 @externallyDefinedApi
2183 /** @fn tmpfile64(void)
2185 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
2190 @externallyDefinedApi
2193 /** @fn tmpnam(char *str)
2196 Refer to tmpfile() for the documentation
2201 @capability Deferred @ref RFs::MkDir(const TDesC16&)
2202 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
2205 @externallyDefinedApi
2208 /** @fn ungetc(int c, FILE *fp)
2211 @return The ungetc function returns the character pushed-back after the conversion,
2212 or EOF if the operation fails.
2213 If the value of the argument c character equals EOF ,
2214 the operation will fail and the fp will remain unchanged.
2216 The ungetc function pushes the character c (converted to an unsigned char)
2217 back onto the input stream pointed to by fp .
2218 The pushed-back characters will be returned by subsequent reads on the
2219 stream (in reverse order).
2220 A successful intervening call,
2221 using the same stream,
2222 to one of the file positioning functions
2223 ( fsetpos or rewind )
2224 will discard the pushed back characters.
2226 One character of push-back is guaranteed,
2227 but as long as there is sufficient memory,
2228 an effectively infinite amount of pushback is allowed.
2230 If a character is successfully pushed-back,
2231 the end-of-file indicator for the stream is cleared.
2232 The file-position indicator is decremented
2233 by each successful call to ungetc ;
2234 if its value was 0 before a call, its value is unspecified after
2240 /* this pushing character to file stream using ungetc */
2246 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
2248 printf("Failed to set text-mode\n");
2251 fp = fopen("c:\input.txt", "w");
2252 fprintf(fp, "%s", "abcdefghijklmn");
2253 fprintf(fp, "%c", '');
2254 fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
2256 char * name = "C:\input.txt";
2257 fp = fopen(name, "w+");
2260 printf ("fopen failed");
2263 if(ungetc('a',fp)!='a') printf("ungetc failed");
2265 fseek(fp,-1,SEEK_CUR);
2267 printf("character read from stream is \"%c\",c);
2275 character read from stream is "a"
2284 @externallyDefinedApi
2287 /** @fn vfprintf(FILE *fp, const char *fmt0, va_list ap)
2292 Refer to printf() for the documentation
2300 @externallyDefinedApi
2303 /** @fn vprintf(const char * fmt, va_list ap)
2307 Refer to printf() for the documentation
2315 @externallyDefinedApi
2318 /** @fn vsprintf(char * str, const char *fmt, va_list ap)
2323 Refer to printf() for the documentation
2331 @externallyDefinedApi
2334 /** @fn snprintf(char * str, size_t n, const char * fmt, ...)
2340 Refer to printf() for the documentation
2348 @externallyDefinedApi
2351 /** @fn vfscanf(FILE * stream, const char * format, va_list ap)
2356 Refer to scanf() for the documentation
2367 @externallyDefinedApi
2370 /** @fn vscanf(const char *fmt, va_list ap)
2374 Refer to scanf() for the documentation
2385 @externallyDefinedApi
2388 /** @fn vsnprintf(char * str, size_t n, const char * fmt, va_list ap)
2394 Refer to printf() for the documentation
2402 @externallyDefinedApi
2405 /** @fn vsscanf(const char * str, const char * format, va_list ap)
2410 Refer to scanf() for the documentation
2421 @externallyDefinedApi
2424 /** @fn fdopen(int fd, const char *mode)
2428 Refer to fopen() for the documentation
2436 @externallyDefinedApi
2439 /** @fn fileno(FILE *fp)
2442 Refer to clearerr() for the documentation
2448 @externallyDefinedApi
2451 /** @fn popen(const char *command, const char *mode)
2457 1. This description also covers the pclose() function.
2459 2. When a child process created using popen() exits, the parent process receives a SIGCHLD signal.
2461 @return The popen function returns NULL if the fork
2463 or if it cannot allocate memory. The pclose function returns -1 if stream is not associated with a "popened" command, if stream already "pclosed" or if wait4
2466 The popen function opens a process by creating a pipe, forking, and invoking
2467 the shell. Since a pipe is by definition unidirectional, the type argument may specify only reading or writing, not both. The resulting
2468 stream is correspondingly read-only ("r") or write-only "w". If type is anything
2469 other than this the behavior is undefined.
2471 The command argument is a pointer to a null-terminated string containing a shell command line.
2472 This command is passed to /bin/sh using the - c flag; interpretation, if any, is performed by the shell.
2474 The return value from popen is a normal standard I/O stream in all respects save that it must be closed with pclose rather than fclose. Writing to such a stream writes to the standard input of the
2475 command. The command's standard output is the same as that of the process
2476 that called popen, unless this is altered by the command itself. Conversely, reading
2477 from a "popened" stream reads the command's standard output, and the command's
2478 standard input is the same as that of the process that called popen.
2480 Note that output popen streams are fully buffered by default.
2482 The pclose function waits for the associated process to terminate
2483 and returns the exit status of the command
2498 Since the standard input of a command opened for reading
2499 shares its seek offset with the process that called popen, if the original process has done a buffered read,
2500 the command's input position may not be as expected.
2501 Similarly, the output from a command opened for writing
2502 may become intermingled with that of the original process.
2503 The latter can be avoided by calling fflush before popen. Failure to execute the shell
2504 is indistinguishable from the shell's failure to execute command,
2505 or an immediate exit of the command.
2506 The only hint is an exit status of 127. The popen function
2507 always calls sh and never calls csh.
2511 @externallyDefinedApi
2514 /** @fn popen3(const char *file, const char *cmd, char** envp, int fds[3])
2516 Open stdin, stdout, and stderr streams and start external executable.
2518 Note: When a child process created using popen3() exits, the parent process receives a SIGCHLD signal.
2521 @externallyDefinedApi
2524 /** @fn ftrylockfile(FILE *fp)
2527 Refer to flockfile() for the documentation
2528 @see getc_unlocked()
2529 @see putc_unlocked()
2533 @externallyDefinedApi
2536 /** @fn flockfile(FILE *fp)
2539 Note: This description also covers the following functions -
2540 ftrylockfile() funlockfile()
2542 @return The flockfile and funlockfile functions return no value. The ftrylockfile function
2543 returns zero if the stream was successfully locked,non-zero otherwise.
2545 These functions provide explicit application-level locking of stdio streams.
2546 They can be used to avoid output from multiple threads being interspersed,
2547 input being dispersed among multiple readers, and to avoid the overhead
2548 of locking the stream for each operation.
2550 The flockfile function acquires an exclusive lock on the specified stream.
2551 If another thread has already locked the stream flockfile will block until the lock is released.
2553 The ftrylockfile function is a non-blocking version of flockfile; if the lock cannot be acquired immediately ftrylockfile returns non-zero instead of blocking.
2555 The funlockfile function releases the lock on a stream acquired by an earlier call to flockfile or ftrylockfile.
2557 These functions behave as if there is a lock count associated with each stream.
2558 Each time flockfile is called on the stream the count is incremented and each
2559 time funlockfile is called on the stream the count is decremented. The
2560 lock is only actually released when the count reaches zero.
2567 #include <pthread.h> //link to the lib -libpthread
2569 void* somefun(void* args)
2571 FILE *fp = (FILE *)args;
2574 printf("aquired lock!");
2575 fputc('a', fp); //fputc_unlocked() is more relevant
2576 printf("after a from thr 2");
2578 printf("after sleep from thr 2");
2580 printf("after b from thr 2");
2582 printf("after c from thr 2");
2590 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
2592 printf("Failed to set text-mode\n");
2595 fp = fopen("c:\chk.txt", "w");
2599 fputc('x', fp); //fputc_unlocked() is more relevant
2600 printf("after x from thr 1");
2602 printf("after sleep from thr 1");
2603 pthread_create(&obj;, NULL, somefun, fp);
2604 printf("after calling thr 2 from thr 1");
2606 printf("after y from thr 1");
2608 printf("after z from thr 1");
2610 printf("gave up lock in thr 1");
2612 pthread_exit((void *)0);
2620 after sleep from thr 1
2622 after calling thr 2 from thr 1
2625 gave up lock in thr 1
2628 after sleep from thr 2
2632 Note: The printing takes quite some time and hence the
2633 output may not look exactly like the above one.
2634 (try printing to the files if you are very particular)
2641 #include <pthread.h> //link to lib -libpthread
2644 void* somefun(void* args)
2647 FILE *fp = (FILE *)args;
2652 int i = ftrylockfile(fp);
2655 printf("aquired lock!");
2657 printf("after a from thr 2");
2659 printf("after sleep from thr 2");
2661 printf("after b from thr 2");
2663 printf("after c from thr 2");
2665 printf("gave up lock in thr 2");
2668 printf("couldn't aquire lock");
2674 if( set_fmode('t') != 0 ) // setting text-mode as default file opening mode throughtout the appln.
2676 printf("Failed to set text-mode\n");
2679 fp = fopen("c:\chk.txt", "w");
2685 printf("after x from thr 1");
2687 printf("after sleep from thr 1");
2688 pthread_create(&obj;, NULL, somefun, fp);
2689 printf("after calling thr 2 from thr 1");
2691 printf("after y from thr 1");
2693 printf("after z from thr 1");
2695 printf("gave up lock in thr 1");
2699 pthread_exit((void *)0);
2707 after sleep from thr 1
2709 couldn't acquire lock
2710 after calling thr 2 from thr 1
2713 gave up lock in thr 1
2715 Note: The printing takes quite some time and hence the
2716 output may not look exactly like the above one.
2717 (try printing to the files if you are very particular)
2721 @see getc_unlocked()
2722 @see putc_unlocked()
2726 @externallyDefinedApi
2729 /** @fn funlockfile(FILE *fp)
2732 Refer to flockfile() for the documentation
2733 @see getc_unlocked()
2734 @see putc_unlocked()
2738 @externallyDefinedApi
2741 /** @fn getc_unlocked(FILE *fp)
2744 Refer to fgetc() for the documentation
2755 @externallyDefinedApi
2758 /** @fn getchar_unlocked(void)
2761 Refer to fgetc() for the documentation
2772 @externallyDefinedApi
2775 /** @fn putc_unlocked(int ch, FILE *fp)
2779 Refer to fputc() for the documentation
2788 @externallyDefinedApi
2791 /** @fn putchar_unlocked(int ch)
2794 Refer to fputc() for the documentation
2803 @externallyDefinedApi
2806 /** @fn getw(FILE *fp)
2809 Refer to fgetc() for the documentation
2820 @externallyDefinedApi
2823 /** @fn putw(int w, FILE *fp)
2827 Refer to fputc() for the documentation
2836 @externallyDefinedApi
2839 /** @fn tempnam(const char *, const char *)
2840 Refer to tmpfile() for the documentation
2842 @externallyDefinedApi
2845 /** @fn asprintf(char **str, const char *fmt, ...)
2850 Refer to printf() for the documentation
2858 @externallyDefinedApi
2861 /** @fn setbuffer(FILE *fp, char *buf, int size)
2866 Refer to setbuf() for the documentation
2874 @externallyDefinedApi
2877 /** @fn setlinebuf(FILE *fp)
2880 Refer to setbuf() for the documentation
2888 @externallyDefinedApi
2891 /** @fn vasprintf(char **str, const char *fmt, va_list ap)
2896 Refer to printf() for the documentation
2904 @externallyDefinedApi
2907 /** @fn ftruncate(int fd, off_t length)
2911 Refer to truncate() for the documentation
2916 @externallyDefinedApi
2919 /** @fn lseek(int fildes, off_t offset, int whence)
2923 @return Upon successful completion, lseek returns the resulting offset location as measured in bytes from the
2924 beginning of the file.
2926 a value of -1 is returned and errno is set to indicate
2929 The lseek system call repositions the offset of the file descriptor fildes to the argument offset according to the directive whence.
2930 The argument fildes must be an open file descriptor. The lseek system call repositions the file position pointer associated with the file descriptor fildes as follows:
2932 If whence is SEEK_SET, the offset is set to offset bytes.
2933 If whence is SEEK_CUR, the offset is set to its current location plus offset bytes.
2934 If whence is SEEK_END, the offset is set to the size of the file plus offset bytes.
2936 Some devices are incapable of seeking. The value of the pointer associated with such a device is undefined.
2938 Note: lseek function allows the file offset to be set beyond the existing end-of-file, data in the seeked slot is undefined, and hence the read operation in seeked slot is
2939 undefined untill data is actually written into it. lseek beyond existing end-of-file increases the file size accordingly.
2945 /* Detailed description : Example for lseek usage.*/
2947 #include <sys/stat.h>
2949 #include <sys/types.h>
2953 fd = open("lseek.txt" , O_CREAT | O_RDWR , 0666);
2954 if(lseek(fd , 0 , SEEK_SET) < 0 ) {
2955 printf("Lseek on file lseek.txt failed");
2958 printf("Lseek on lseek.txt passed ");
2966 Lseek on lseek.txt passed
2974 @externallyDefinedApi
2978 /** @fn truncate(const char *path, off_t length)
2982 Note: This description also covers the following functions -
2985 @return Upon successful completion, both truncate() and ftruncate() return 0; otherwise,
2986 they return -1 and set errno to indicate the error.
2988 The truncate system call
2989 causes the file named by path or referenced by fd to be truncated to length bytes in size.
2991 was larger than this size, the extra data
2993 If the file was smaller than this size,
2994 it will be extended as if by writing bytes with the value zero.
2996 the file must be open for writing.
3000 //example for truncate
3003 #include <sys/stat.h>
3006 int retVal, retVal2, retSize, retSize2;
3009 char *buffer = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx";
3010 int fp = open("c: est.txt", O_RDWR|O_CREAT);
3011 size = write(fp,buffer,50);
3013 retVal2 = stat("c: est.txt", &buf; );
3016 retSize = buf.st_size;
3017 printf("Size before: %d", retSize);
3018 retVal = truncate("c: est.txt", retSize/2 );
3024 retVal2 = stat( "c: est.txt", &buf; );
3027 retSize2 = buf.st_size;
3028 if( retSize2 == (retSize/2 ) )
3030 printf("Size after: %d", retSize2);
3031 printf("Truncate passed");
3054 //example for ftruncate
3057 int test_ftruncate()
3059 //assuming that the file exists and has some //data in it
3060 int fp = open("c: est.txt", O_RDWR);
3061 int retVal, retVal2, retSize, retSize2;
3065 retVal2 = fstat( fp, &buf; );
3068 retSize = buf.st_size;
3069 printf("Size before: %d", retSize);
3070 retVal = ftruncate( fp, retSize/2 );
3077 fp = open("c: est.txt", O_RDONLY);
3078 if((fp != -1) && (!retVal))
3080 retVal2 = fstat( fp, &buf; );
3083 retSize2 = buf.st_size;
3084 if( retSize2 == (retSize/2 ) )
3086 printf("Size after: %d", retSize2);
3087 printf("Ftruncate Passed");
3112 These calls should be generalized to allow ranges
3113 of bytes in a file to be discarded. Use of truncate to extend a file is not portable.
3117 @externallyDefinedApi
3120 /** @fn int setecho(int fd, uint8_t echoval)
3124 Turns On/Off the echo for the input characters.
3125 If echoval is 0, the echo is turned off and nothing gets echoed on the console.
3126 If echoval is 1, the echo is turned on.
3127 If echoval is anything else, the echo is turned off and the given printable character
3128 will be echoed instead the actual input character.
3131 The given fd should be that of a console.
3132 If the stdio redirection server is used to redirect the stdin/stdout of a process and
3133 if the given fd maps to one of those, then the stdin will only be affected by this call.
3134 Write operations on this fd will not be affected.
3135 The earlier behavior is retained if setecho() fails.
3137 @return Upon successfull completion it returns 0, otherwise -1, setting the errno.
3140 @externallyDefinedApi
3145 The type va_list is defined for variables used to traverse the list.
3148 @externallyDefinedApi
3153 To be used for vfscanf(..)
3156 @externallyDefinedApi
3164 @externallyDefinedApi
3172 @externallyDefinedApi
3180 @externallyDefinedApi
3188 @externallyDefinedApi
3193 open for reading & writing
3196 @externallyDefinedApi
3204 @externallyDefinedApi
3212 @externallyDefinedApi
3220 @externallyDefinedApi
3225 fdopen()ed in append mode
3228 @externallyDefinedApi
3233 this is an sprintf or snprintf string
3236 @externallyDefinedApi
3241 do fseek() optimization
3244 @externallyDefinedApi
3249 do not do fseek() optimization
3252 @externallyDefinedApi
3257 set iff _offset is in fact correct
3260 @externallyDefinedApi
3265 true; fgetln modified _p text
3268 @externallyDefinedApi
3273 allocate string space dynamically
3276 @externallyDefinedApi
3281 ignore this file in _fwalk
3284 @externallyDefinedApi
3289 setvbuf should set fully buffered
3292 @externallyDefinedApi
3297 setvbuf should set line buffered
3300 @externallyDefinedApi
3305 setvbuf should set unbuffered
3308 @externallyDefinedApi
3313 size of buffer used by setbuf
3316 @externallyDefinedApi
3324 @externallyDefinedApi
3329 must be less than OPEN_MAX
3332 @externallyDefinedApi
3335 /** @def FILENAME_MAX
3337 must be less than PATH_MAX
3340 @externallyDefinedApi
3345 set file offset to EOF plus offset
3348 @externallyDefinedApi
3353 set file offset to current plus offset
3356 @externallyDefinedApi
3361 set file offset to offset
3364 @externallyDefinedApi
3372 @externallyDefinedApi
3380 @externallyDefinedApi
3385 standard input variable
3388 @externallyDefinedApi
3393 standard output variable
3396 @externallyDefinedApi
3401 standard error variable
3404 @externallyDefinedApi
3412 @externallyDefinedApi
3420 @externallyDefinedApi
3424 /** @def __isthreaded
3426 defined to isthreaded()
3429 @externallyDefinedApi
3434 Functions defined in ANSI C standard.
3437 @externallyDefinedApi
3442 Functions defined in ANSI C standard.
3445 @externallyDefinedApi
3448 /** @def clearerr(p)
3450 Functions defined in ANSI C standard.
3453 @externallyDefinedApi
3458 Functions defined in ANSI C standard.
3461 @externallyDefinedApi
3466 Functions defined in ANSI C standard.
3469 @externallyDefinedApi
3474 Defined to getc(stdin)
3477 @externallyDefinedApi
3482 defined to putc(x,stdout)
3485 @externallyDefinedApi
3493 @externallyDefinedApi
3496 /** @var __sbuf::_base
3497 Pointer to the buffer
3500 /** @var __sbuf::_size
3506 stdio state file variables.
3509 @externallyDefinedApi
3512 /** @typedef typedef __off_t fpos_t
3514 Represents file position
3517 @externallyDefinedApi
3520 /** @typedef typedef __off_t fpos64_t
3522 Represents large file position
3525 @externallyDefinedApi
3528 /** @typedef typedef __size_t size_t
3530 A type to define sizes of strings and memory blocks.
3533 @externallyDefinedApi
3536 /** @typedef typedef __va_list va_list
3538 A void pointer which can be interpreted as an argument list.
3541 @externallyDefinedApi
3545 /** @fn tmpdirname(void)
3547 @return Upon successful completion tmpdirname() will return the path of the private directory of that process.
3549 Note:String that the function will return is not to be modified.
3555 /* Illustrates how to use tmpdirname() API */
3570 /** @fn set_fmode(char mode)
3572 @return set_fmode() returns 0 on success, otherwise returns -1 with an errno set to EINVAL.
3574 set_fmode(), get_fmode() are used to provide text-mode support.
3576 Using set_fmode(), User can set file opening mode explicitly to either text or binary i.e. it can take only 't' or 'b' as parameter.
3578 Notes: 1>. User is supposed to use this before opening a file or at the start of the application. The mode that is set using set_fmode()
3579 is fixed till the file is closed or till the application terminates. In case the user wants to change the mode once the file
3580 has been opened and before it is closed, the buffer needs to be flushed explicitly.
3582 2>. If the user mixes the two file modes, there might be unexpected behaviour.
3583 For example, a file is opened in text mode, written with 20 bytes and closed.
3584 Again the file is opened in binary mode and 20 bytes is read. If the 20 bytes written earlier had '\n's among them,
3585 the read data will not be complete.
3590 * Detailed description : To set the mode of a file to either text/binary explicitly
3596 ret = set_fmode('t');
3599 printf("Failed to set text mode\n") ;
3602 printf("Successfully able to set text mode\n") ;
3603 if (get_fmode() != 't')
3605 printf("Failed to Retrieve file-mode\n") ;
3608 printf("Successfully able to Retrieve file-mode\n") ;
3631 @externallyDefinedApi
3634 /** @fn get_fmode( )
3635 @return get_fmode() returns the current file open mode as either 't' or 'b'. 't' is returned if text-mode is set
3636 explicitly using set_fmode(), otherwise 'b' binary-mode is returned which is default in symbian.
3641 * Detailed description : To Retrieve the current mode of a file
3647 ret = set_fmode('t');
3650 printf("Failed to set text mode\n") ;
3653 printf("Successfully able to set text mode\n") ;
3654 if (get_fmode() != 't')
3656 printf("Failed to Retrieve file-mode\n") ;
3659 printf("Successfully able to Retrieve file-mode\n") ;
3669 * Detailed description : General example to illustrate set_fmode(), get_fmode()
3674 char *data = "helloworld\nfine";
3677 FILE *fw = NULL, *fr = NULL;
3679 ret = set_fmode('t'); // To set text-mode using set_fmode()
3682 printf("Failed to set text mode") ;
3685 if (get_fmode() != 't')
3687 printf("Failed to Retrieve file-mode") ;
3691 fw = fopen("c:\\temp_tc.txt", "w");
3692 int count = fwrite(data, 1, strlen(data), fw);
3693 if(count != strlen(data))
3695 printf("fwrite() failed\n");
3699 fw = fopen("c:\\temp_tc_out.txt", "w");
3700 fr = fopen("c:\\temp_tc.txt", "r");
3701 p = (char *)malloc(count+1); // extra one is for holding '\0'
3704 printf("malloc() failed\n");
3707 char *retn = fgets(p, count, fr);
3708 //ret = fread(p, 1, 11, fr);
3711 printf("1st read failed\n");
3714 int pos = ftell(fr); // 12 -> offset
3715 printf("pos After 1st read: %d\n", pos);
3716 fseek(fr,pos,SEEK_SET);
3717 ret = fread(p+11,1,4,fr);
3720 printf("Failed to read using fread()\n");
3724 pos = ftell(fr); // 16 -> offset
3725 printf("pos After 2nd read: %d\n", pos);
3727 count = fwrite(p, 1, strlen(p), fw);
3728 if(count != strlen(p))
3730 printf(" Failed to write onto another file\n");
3735 printf("Passed to write onto another file\n");
3755 pos After 1st read: 12
3756 pos After 2nd read: 20
3757 Passed to write onto another file
3764 @externallyDefinedApi