genericopenlibs/openenvcore/include/stdio.dosc
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /** @file ../include/stdio.h
       
     2 @internalComponent
       
     3 */
       
     4 
       
     5 /** @fn  clearerr(FILE *fp)
       
     6 @param fp
       
     7 
       
     8 Note: This description also covers the following functions -
       
     9  feof()  ferror()  fileno() 
       
    10 
       
    11   The function clearerr clears the end-of-file and error indicators for the stream pointed
       
    12 to by fp.
       
    13 
       
    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.
       
    16 
       
    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.
       
    19 
       
    20  The function fileno examines the argument fp and returns its integer descriptor.
       
    21  
       
    22 Examples:
       
    23 @code
       
    24 /* this program shows finding error set using ferror 
       
    25  * and clearing it using clearerr functions */
       
    26 #include <stdio.h>
       
    27 int main()
       
    28 {
       
    29         char a;
       
    30         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughout the appln.
       
    31         	{
       
    32         	printf("Failed to set text-mode\n");
       
    33         	return -1;
       
    34         	}
       
    35         FILE* fp = fopen("c:\input.txt", "w");
       
    36         fprintf(fp, "%s", "abcdefghijklmn");
       
    37         fprintf(fp, "%c", '');
       
    38         fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
       
    39         fclose(fp);
       
    40         fp=fopen("c:\input.txt","r");
       
    41         if (fp == NULL)
       
    42                 {
       
    43                 printf("fopen failed");
       
    44                 return -1;
       
    45                 }
       
    46         else
       
    47                 {
       
    48                 fwrite(&a;, sizeof(char), 1, fp);
       
    49                 if (ferror (fp))
       
    50                         printf("error set in file stream");
       
    51                 else
       
    52                         {
       
    53                         fclose(fp);
       
    54                         return -1;
       
    55                         }
       
    56                 clearerr(fp);
       
    57                 if (!ferror(fp))
       
    58                         printf("error cleared in file stream");
       
    59                 else printf("error still unexpected set in file stream");
       
    60                 fclose (fp);
       
    61                 }
       
    62         return 0;
       
    63 }
       
    64 
       
    65 @endcode
       
    66 @code
       
    67 Output
       
    68 
       
    69 error set in file stream
       
    70 error cleared in file stream
       
    71 
       
    72 @endcode
       
    73 @see open()
       
    74 @see flockfile()
       
    75 @see set_fmode() 
       
    76 
       
    77 @publishedAll
       
    78 @externallyDefinedApi
       
    79 */
       
    80 
       
    81 /** @fn  fclose(FILE *fp)
       
    82 @param 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.
       
    86 
       
    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 .
       
    89 
       
    90 Examples:
       
    91 @code
       
    92 /* this program shows opening and closing of a file using fclose api */
       
    93 #include <stdio.h>
       
    94 int main()
       
    95 {
       
    96         FILE *fp;
       
    97         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughout the appln.
       
    98         	{
       
    99         	printf("Failed to set text-mode\n");
       
   100         	return -1;
       
   101         	}
       
   102         fp = fopen("c:\input.txt", "w+");
       
   103         if(fp == NULL)
       
   104                 {               
       
   105                 printf("file opening failed");
       
   106                 return -1;
       
   107                 }
       
   108         
       
   109         printf("file opened successfully: Perform file operations now");
       
   110         
       
   111         if(!fclose(fp))
       
   112                 {
       
   113                 printf("file closed successfully");
       
   114                 return 0;
       
   115                 }
       
   116         else
       
   117                 {
       
   118                 printf("file closing failed");
       
   119                 return -1;
       
   120                 }
       
   121 }
       
   122 
       
   123 @endcode
       
   124 @code
       
   125 Output
       
   126 
       
   127 file opened successfully: Perform file operations now
       
   128 file closed successfully
       
   129 
       
   130 @endcode
       
   131 
       
   132 Notes:
       
   133 
       
   134  The fclose function
       
   135 does not handle NULL arguments; they will result in a segmentation
       
   136 violation.
       
   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 
       
   139 rely upon it. 
       
   140  
       
   141 
       
   142 @publishedAll
       
   143 @externallyDefinedApi
       
   144 */
       
   145 
       
   146 /** @fn  feof(FILE *fp)
       
   147 @param fp
       
   148 
       
   149 Refer to  clearerr() for the documentation
       
   150 @see open()
       
   151 @see flockfile()
       
   152 @see set_fmode()
       
   153 
       
   154  
       
   155 
       
   156 @publishedAll
       
   157 @externallyDefinedApi
       
   158 */
       
   159 
       
   160 /** @fn  ferror(FILE *fp)
       
   161 @param fp
       
   162 
       
   163 Refer to  clearerr() for the documentation
       
   164 @see open()
       
   165 @see flockfile()
       
   166  
       
   167 
       
   168 @publishedAll
       
   169 @externallyDefinedApi
       
   170 */
       
   171 
       
   172 /** @fn  fseeko(FILE *stream, off_t offset, int whence)
       
   173 @param stream
       
   174 @param offset
       
   175 @param whence
       
   176 
       
   177 For full documentation see: http://opengroup.org/onlinepubs/007908775/xsh/fseek.html
       
   178 
       
   179 @see fseek()
       
   180  
       
   181 @publishedAll
       
   182 @externallyDefinedApi
       
   183 */
       
   184 
       
   185 /** @fn  fseeko64(FILE *stream, off64_t offset, int whence)
       
   186 @param stream
       
   187 @param offset
       
   188 @param whence
       
   189 
       
   190 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
       
   191 
       
   192 @see fseeko()
       
   193  
       
   194 @publishedAll
       
   195 @externallyDefinedApi
       
   196 */
       
   197 
       
   198 /** @fn  ftello(FILE *stream)
       
   199 @param stream
       
   200 
       
   201 For full documentation see: http://opengroup.org/onlinepubs/007908775/xsh/fseek.html
       
   202 
       
   203 @see ftell()
       
   204  
       
   205 @publishedAll
       
   206 @externallyDefinedApi
       
   207 */
       
   208 
       
   209 /** @fn  ftello64(FILE *stream)
       
   210 @param stream
       
   211 
       
   212 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
       
   213 
       
   214 @see ftello()
       
   215  
       
   216 @publishedAll
       
   217 @externallyDefinedApi
       
   218 */
       
   219 
       
   220 /** @fn  fflush(FILE *fp)
       
   221 @param fp
       
   222 
       
   223 @return   Upon successful completion 0 is returned.
       
   224 Otherwise, EOF is returned and the global variable errno is set to indicate the error.
       
   225 
       
   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.
       
   228 
       
   229  If the fp argument is NULL, fflush flushes all open output streams.
       
   230  
       
   231 Examples:
       
   232 @code
       
   233 /* this program shows flushing user space buffered data using fflush */
       
   234 #include <stdio.h>
       
   235 int main()
       
   236 {
       
   237         FILE *fp = NULL;
       
   238         int retval = 0;
       
   239         char name[20] = "c:\flush1.txt";
       
   240         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughout the appln.
       
   241         	{
       
   242         	printf("Failed to set text-mode\n");
       
   243         	return -1;
       
   244         	}
       
   245         fp = fopen(name, "w+"); 
       
   246         if(fp == NULL)
       
   247                 {               
       
   248                 printf("Error : File open");
       
   249                 return -1;
       
   250                 }
       
   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.");
       
   253         
       
   254         retval = fflush(fp);
       
   255         if (retval)
       
   256                 {               
       
   257                 printf("fflush failed");
       
   258                 fclose(fp);
       
   259                 unlink(name);
       
   260                 return -1;
       
   261                 }
       
   262         else printf("Buffer successfully flushed");
       
   263         fclose(fp);
       
   264         unlink(name);
       
   265         return 0;
       
   266 }
       
   267 
       
   268 @endcode
       
   269 @code
       
   270 Output
       
   271 
       
   272 we are trying to buffer 100 characters at once with NULL buffer.
       
   273 Buffer successfully flushed
       
   274 
       
   275 @endcode
       
   276 @see write()
       
   277 @see fclose()
       
   278 @see fopen()
       
   279 @see setbuf()
       
   280 @see set_fmode()
       
   281  
       
   282 
       
   283 @publishedAll
       
   284 @externallyDefinedApi
       
   285 */
       
   286 
       
   287 /** @fn  fgetc(FILE *fp)
       
   288 @param fp
       
   289 
       
   290 Note: This description also covers the following functions -
       
   291  getc()  getc_unlocked()  getchar()  getchar_unlocked()  getw() 
       
   292 
       
   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
       
   300 
       
   301   The fgetc function
       
   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.
       
   303 
       
   304  The getc function
       
   305 acts essentially identically to fgetc, but is a macro that expands in-line.
       
   306 
       
   307  The getchar function
       
   308 is equivalent to getc (stdin.);
       
   309 
       
   310  The getw function
       
   311 obtains the next int
       
   312 (if present)
       
   313 from the stream pointed at by stream.
       
   314 
       
   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.
       
   321 
       
   322 Examples:
       
   323 @code
       
   324 /* this program shows reading from file using getc */
       
   325 /* consider input.txt has the following content: */
       
   326 /* hi */
       
   327 #include <stdio.h>
       
   328 int main(void)
       
   329 {
       
   330         int retval;
       
   331         FILE *fp = NULL;
       
   332         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughout the appln.
       
   333         	{
       
   334         	printf("Failed to set text-mode\n");
       
   335         	return -1;
       
   336         	}
       
   337         fp = fopen("c:\input.txt", "w");
       
   338         fprintf(fp, "%s", "abcdefghijklmn");
       
   339         fprintf(fp, "%c", '\n');
       
   340         fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
       
   341         fclose(fp);
       
   342         fp = fopen("C:\input.txt","r");
       
   343         if(fp == NULL)
       
   344         {
       
   345         printf("fopen failed");
       
   346         return -1;
       
   347         }
       
   348         while((int)(retval = getc(fp) )!= EOF)
       
   349         {
       
   350         printf("%c", retval);
       
   351         }
       
   352         fclose(fp);
       
   353         return 0;
       
   354 }
       
   355 
       
   356 @endcode
       
   357 @code
       
   358 Output
       
   359 
       
   360 hi
       
   361 
       
   362 @endcode
       
   363 @see ferror()
       
   364 @see flockfile()
       
   365 @see fopen()
       
   366 @see fread()
       
   367 @see getwc()
       
   368 @see putc()
       
   369 @see ungetc()
       
   370 @see set_fmode()
       
   371  
       
   372 
       
   373 @publishedAll
       
   374 @externallyDefinedApi
       
   375 */
       
   376 
       
   377 /** @fn  fgetpos(FILE * fp, fpos_t * pos)
       
   378 @param fp
       
   379 @param pos
       
   380 Refer to  fseek() for the documentation
       
   381 @see lseek()
       
   382 @see ungetc()
       
   383 @see ungetwc()
       
   384  
       
   385 
       
   386 @publishedAll
       
   387 @externallyDefinedApi
       
   388 */
       
   389 
       
   390 /** @fn  fgetpos64(FILE * fp, fpos64_t * pos)
       
   391 @param fp
       
   392 @param pos
       
   393 
       
   394 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
       
   395 
       
   396 
       
   397 @see fgetpos()
       
   398 
       
   399 @publishedAll
       
   400 @externallyDefinedApi
       
   401 */
       
   402 
       
   403 /** @fn  fgets(char *buf, int n, FILE *fp)
       
   404 @param buf
       
   405 @param n
       
   406 @param fp
       
   407 
       
   408 Note: This description also covers the following functions -
       
   409  gets() 
       
   410 
       
   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.
       
   415 
       
   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.
       
   419 
       
   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.
       
   423 
       
   424 Examples:
       
   425 @code
       
   426 /* this program shows reading characters from a file using fgets */
       
   427 /* consider input.txt has the following content: */
       
   428 /* abcdefghijklmn */
       
   429 /* fdsfdsafsdabcdefghijklmn */
       
   430 #include <stdio.h>
       
   431 int main(void)
       
   432 {
       
   433         char buf[20];
       
   434         FILE *fp = NULL;
       
   435         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughout the appln.
       
   436         	{
       
   437         	printf("Failed to set text-mode\n");
       
   438         	return -1;
       
   439         	}
       
   440        	fp = fopen("c:\input.txt", "w");
       
   441         fprintf(fp, "%s", "abcdefghijklmn");
       
   442         fprintf(fp, "%c", "");
       
   443         fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
       
   444         fclose(fp);
       
   445                 
       
   446         fp = fopen("C:\input.txt","r");
       
   447         if(fp == NULL)
       
   448                 {
       
   449                 printf("fopen failed");
       
   450                 return -1;
       
   451                 }
       
   452         if(fgets(buf,18,fp) != NULL)
       
   453                 printf("%s", buf);
       
   454         else
       
   455                 printf("Buffer is empty");
       
   456         
       
   457         buf[0] = '\0';
       
   458         if(fgets(buf,2,fp) != NULL)
       
   459                 printf("%s", buf);
       
   460         else
       
   461                 printf("Buffer is empty");
       
   462         fclose(fp);     
       
   463         return 0;
       
   464 }
       
   465 
       
   466 @endcode
       
   467 @code
       
   468 Output
       
   469 
       
   470 abcdefghijklmn
       
   471 fdsfdsafsdabcdefghijklmn
       
   472 
       
   473 @endcode
       
   474 
       
   475 Security considerations:
       
   476 
       
   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.
       
   482 @see feof()
       
   483 @see ferror()
       
   484 @see fgetln()
       
   485 @see set_fmode()
       
   486  
       
   487 
       
   488 @publishedAll
       
   489 @externallyDefinedApi
       
   490 */
       
   491 
       
   492 /** @fn  fopen(const char *file, const char *mode)
       
   493 @param file
       
   494 @param mode
       
   495 
       
   496 Note: This description also covers the following functions -
       
   497  fdopen()  freopen() 
       
   498 
       
   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.
       
   501 
       
   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(). 
       
   504 	          
       
   505 The  fopen function opens the file whose name is the string pointed to by  file and associates a stream with it.
       
   506 
       
   507 The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):
       
   508 @code
       
   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.
       
   515 @endcode
       
   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.
       
   517 
       
   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.
       
   519 
       
   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.
       
   521 
       
   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.
       
   523 
       
   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.
       
   525 
       
   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:
       
   527 @code
       
   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. 
       
   532 @endcode
       
   533 The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout). 
       
   534 
       
   535 
       
   536 
       
   537 Examples:
       
   538 @code
       
   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 */
       
   542 #include <stdio.h>
       
   543 int main(void)
       
   544 {
       
   545         FILE *fp;       
       
   546         char name[20] = "c:\fopen1.txt";
       
   547         
       
   548         if ((fp = fopen (name, "w")) == NULL)	// Opens file in default binary mode
       
   549         {
       
   550         printf("Error creating file");
       
   551         return -1;
       
   552         }
       
   553         printf("Opened file");
       
   554         fprintf(fp, "helloworld\n");
       
   555         printf("Wrote to file");
       
   556       	fclose (fp);
       
   557       	printf("Closed file");
       
   558       	if ((fp = fopen (name, "a")) == NULL)
       
   559       		{
       
   560       		printf("Error opening file");
       
   561       		return -1;
       
   562       		}
       
   563       	printf("Opened file for appending");
       
   564 	    fprintf(fp, "fine");
       
   565 	    fclose (fp);
       
   566 	    printf("closed file, check output in c:\ fopen.txt file");
       
   567 	    unlink(name);
       
   568 	    return 0;
       
   569 }
       
   570 
       
   571 @endcode
       
   572 @code
       
   573 Output
       
   574 
       
   575 Opened file
       
   576 Wrote to file
       
   577 Closed file
       
   578 Opened file for appending
       
   579 closed file, check output in c:\fopen.txt file
       
   580 
       
   581 Note: fopen.txt file contains:-
       
   582 helloworld\nfine
       
   583 
       
   584 @endcode
       
   585 
       
   586 
       
   587 @code
       
   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 */
       
   591 #include <stdio.h>
       
   592 int main(void)
       
   593 {
       
   594         FILE *fp;       
       
   595         char name[20] = "c:\fopen1.txt";
       
   596         if( set_fmode('t') != 0 )
       
   597         	{
       
   598         	printf("Failed to set text-mode\n");
       
   599         	return -1;
       
   600         	}
       
   601         if(get_fmode() != 't')
       
   602         	{
       
   603         	printf(" Failed to retrieve the text-mode set using set_fmode()\n");
       
   604         	return -1;
       
   605         	}
       
   606         if ((fp = fopen (name, "w")) == NULL) // Opens file in text-mode
       
   607         {
       
   608         printf("Error creating file");
       
   609         return -1;
       
   610         }
       
   611         printf("Opened file");
       
   612         fprintf(fp, "helloworld\n");
       
   613         printf("Wrote to file");
       
   614       	fclose (fp);
       
   615       	printf("Closed file");
       
   616       	if ((fp = fopen (name, "a")) == NULL)
       
   617       		{
       
   618       		printf("Error opening file");
       
   619       		return -1;
       
   620       		}
       
   621       	printf("Opened file for appending");
       
   622 	    fprintf(fp, "fine");
       
   623 	    fclose (fp);
       
   624 	    printf("closed file, check output in c:\ fopen.txt file");
       
   625 	    unlink(name);
       
   626 	    return 0;
       
   627 }
       
   628 
       
   629 @endcode
       
   630 @code
       
   631 Output
       
   632 
       
   633 Opened file
       
   634 Wrote to file
       
   635 Closed file
       
   636 Opened file for appending
       
   637 closed file, check output in c:\fopen.txt file
       
   638 
       
   639 Note: fopen.txt file contains:-
       
   640 helloworld
       
   641 fine
       
   642 
       
   643 @endcode
       
   644 
       
   645 
       
   646 Notes:
       
   647 
       
   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.
       
   655 
       
   656 Limitations: 
       
   657 
       
   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.
       
   664 
       
   665 KErrNotReady of symbian error code is mapped to ENOENT, which typically means drive
       
   666 not found or filesystem not mounted on the drive.
       
   667 
       
   668 @see open()
       
   669 @see fclose()
       
   670 @see fileno()
       
   671 @see fseek()
       
   672 @see set_fmode()
       
   673 @see get_fmode()
       
   674 
       
   675 
       
   676 
       
   677 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
       
   678 
       
   679 @publishedAll
       
   680 @externallyDefinedApi
       
   681 */
       
   682 
       
   683 /** @fn  fopen64(const char *file, const char *mode)
       
   684 @param file
       
   685 @param mode
       
   686 
       
   687 
       
   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.
       
   690 
       
   691 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
       
   692 
       
   693 @see fopen()
       
   694 
       
   695 @publishedAll
       
   696 @externallyDefinedApi
       
   697 */
       
   698 
       
   699 /** @fn  fprintf(FILE *fp, const char *fmt, ...)
       
   700 @param fp
       
   701 @param fmt
       
   702 @param ...
       
   703 
       
   704 Refer to  printf() for the documentation
       
   705 @see printf()
       
   706 @see scanf()
       
   707 @see setlocale()
       
   708 @see wprintf()
       
   709  
       
   710 
       
   711 @publishedAll
       
   712 @externallyDefinedApi
       
   713 */
       
   714 
       
   715 /** @fn  fputc(int c, FILE *fp)
       
   716 @param c
       
   717 @param fp
       
   718 
       
   719 Note: This description also covers the following functions -
       
   720  putc()  putc_unlocked()  putchar()  putchar_unlocked()  putw() 
       
   721 
       
   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.
       
   726 
       
   727 The fputc function writes the character c (converted to an "unsigned char")
       
   728 to the output stream pointed to by fp.
       
   729 
       
   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.
       
   732 
       
   733 The putchar function is identical to putc with an output stream of stdout.
       
   734 
       
   735 The putw function writes the specified int to the named output stream.
       
   736 
       
   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.
       
   741 	
       
   742 	
       
   743 Examples:
       
   744 @code
       
   745 #include <stdio.h>
       
   746 int main()
       
   747 {
       
   748         FILE * fp;
       
   749         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughout the appln.
       
   750         	{
       
   751         	printf("Failed to set text-mode\n");
       
   752         	return -1;
       
   753         	}
       
   754         fp=fopen("C:\input.txt","w+");
       
   755         
       
   756         if(fp==NULL)
       
   757                 {
       
   758                 printf("file opening failed");
       
   759                 return -1;
       
   760                 }
       
   761         if(putc('a',fp)!='a')
       
   762                 {
       
   763                 printf("putc failed");
       
   764                 fclose(fp);
       
   765                 return -1;
       
   766                 }
       
   767         else printf("character successfully put by putc");
       
   768         
       
   769         fclose(fp);
       
   770         return 0;
       
   771 }
       
   772 
       
   773 @endcode
       
   774 @code
       
   775 Output
       
   776 
       
   777 character successfully put by putc
       
   778 
       
   779 @endcode
       
   780 @see ferror()
       
   781 @see flockfile()
       
   782 @see fopen()
       
   783 @see getc()
       
   784 @see putwc()
       
   785 @see set_fmode() 
       
   786 
       
   787 @publishedAll
       
   788 @externallyDefinedApi
       
   789 */
       
   790 
       
   791 /** @fn  fputs(const char *s, FILE *fp)
       
   792 @param s
       
   793 @param fp
       
   794 
       
   795 Note: This description also covers the following functions -
       
   796  puts() 
       
   797 
       
   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.
       
   799 
       
   800   The function fputs writes the string pointed to by s to the stream pointed to by fp.
       
   801 
       
   802  The function puts writes the string s, and a terminating newline character,
       
   803 to the stream stdout.
       
   804 
       
   805 
       
   806 Examples:
       
   807 @code
       
   808 /*this program shows writing characters from a file using fputs */
       
   809 /* consider input.txt has the following content: */
       
   810 /* hello world */
       
   811 #include <stdio.h>
       
   812 int main(void)
       
   813 {
       
   814         int wretval;    
       
   815         char rs1[50],rs2[50];
       
   816         char *rptr;
       
   817         int retval;
       
   818         FILE *fp = NULL;
       
   819         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughout the appln.
       
   820         	{
       
   821         	printf("Failed to set text-mode\n");
       
   822         	return -1;
       
   823         	}
       
   824         fp = fopen("c:\input.txt", "w");
       
   825         fprintf(fp, "%s", "abcdefghijklmn");
       
   826         fprintf(fp, "%c", "");
       
   827         fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
       
   828         fclose(fp);
       
   829         fp = fopen("c:\input.txt","r");
       
   830         if(fp == NULL)
       
   831         {
       
   832         printf("fopen failed");
       
   833         return -1;
       
   834         }
       
   835         rptr = fgets(rs1,12,fp);
       
   836         if(rptr == NULL)
       
   837         {
       
   838         printf("fgets failed");
       
   839         fclose(fp);
       
   840         return -1;
       
   841         }
       
   842         fclose(fp);
       
   843         fp = fopen("c:\puts1.txt","w+");
       
   844         if(fp == NULL)
       
   845         {
       
   846         printf("fopen failed");
       
   847         return -1;
       
   848         }
       
   849         wretval = fputs(rs1,fp);
       
   850         if(wretval == EOF)
       
   851         {
       
   852         printf("fputs failed");
       
   853         fclose(fp);
       
   854         return -1;
       
   855         }
       
   856         fclose(fp);
       
   857         fp = fopen("C:\puts1.txt","r");
       
   858         if(fp == NULL)
       
   859         {
       
   860         printf("fopen failed");
       
   861         return -1;
       
   862         }
       
   863         rptr = fgets(rs2,12,fp);
       
   864         if(rptr == NULL)
       
   865         {
       
   866         printf("fgets failed");
       
   867         fclose(fp);
       
   868         return -1;
       
   869         }
       
   870         printf("file reading returned \"%s\",rs2);
       
   871         fclose(fp);
       
   872         unlink("C:\puts1.txt");
       
   873         
       
   874         return 0;
       
   875 }
       
   876 
       
   877 @endcode
       
   878 @code
       
   879 Output
       
   880 
       
   881 file reading returned "abcdefghijk"
       
   882 
       
   883 @endcode
       
   884 @see ferror()
       
   885 @see fputws()
       
   886 @see putc()
       
   887 @see set_fmode() 
       
   888 
       
   889 @publishedAll
       
   890 @externallyDefinedApi
       
   891 */
       
   892 
       
   893 /** @fn  fread(void * buf, size_t size, size_t count, FILE * fp)
       
   894 @param buf
       
   895 @param size
       
   896 @param count
       
   897 @param fp
       
   898 
       
   899 Note: This description also covers the following functions -
       
   900  fwrite() 
       
   901 
       
   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.
       
   908 
       
   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.
       
   910 
       
   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.
       
   912  
       
   913 
       
   914 Examples:
       
   915 @code
       
   916 /* this program shows reading characters from a file using fread */
       
   917 /* consider input.txt has the following content: */
       
   918 /* hi */
       
   919 #include <stdio.h>
       
   920 int main()
       
   921 {
       
   922         char a; 
       
   923         FILE *fp = NULL;
       
   924         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
   925         	{
       
   926         	printf("Failed to set text-mode\n");
       
   927         	return -1;
       
   928         	}
       
   929         fp = fopen("c:\input.txt", "w");
       
   930         fprintf(fp, "%s", "abcdefghijklmn");
       
   931         fprintf(fp, "%c", '\n');
       
   932         fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
       
   933         fclose(fp);
       
   934         fp = fopen("c:\input.txt", "r");
       
   935         if (fp == NULL)
       
   936                 {
       
   937                 printf ("fopen failed");
       
   938                 return -1;
       
   939                 }
       
   940         // read single chars at a time, stopping on EOF or error:
       
   941         while (fread(&a;, sizeof(char), 1, fp), !feof(fp) && !ferror(fp))
       
   942                 {
       
   943                 printf("I read \"%c\",a);
       
   944                 }
       
   945         if (ferror(fp)) //Some error occurred
       
   946                 {
       
   947                 fclose(fp);
       
   948                 return -1;
       
   949                 }
       
   950         fclose(fp);
       
   951         return 0;
       
   952 }
       
   953 
       
   954 @endcode
       
   955 @code
       
   956 Output
       
   957 
       
   958 I read "h"
       
   959 I read "i"
       
   960 
       
   961 @endcode
       
   962 @see read()
       
   963 @see write()
       
   964 @see set_fmode() 
       
   965 
       
   966 @publishedAll
       
   967 @externallyDefinedApi
       
   968 */
       
   969 
       
   970 /** @fn  freopen(const char *file, const char *mode, FILE *fp)
       
   971 @param file
       
   972 @param mode
       
   973 @param fp
       
   974 
       
   975 Refer to  fopen() for the documentation
       
   976 @see open()
       
   977 @see fclose()
       
   978 @see fileno()
       
   979 @see fseek()
       
   980 
       
   981 
       
   982 
       
   983 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
       
   984 
       
   985 @publishedAll
       
   986 @externallyDefinedApi
       
   987 */
       
   988 
       
   989 /** @fn  freopen64(const char *file, const char *mode, FILE *fp)
       
   990 @param file
       
   991 @param mode
       
   992 @param fp
       
   993 
       
   994 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
       
   995 
       
   996 @see freopen()
       
   997 
       
   998 @publishedAll
       
   999 @externallyDefinedApi
       
  1000 */
       
  1001 
       
  1002 /** @fn  fscanf(FILE *  fp, const char *  fmt, ...)
       
  1003 @param fp
       
  1004 @param fmt
       
  1005 @param ...
       
  1006 
       
  1007 Refer to  scanf() for the documentation
       
  1008 @see getc()
       
  1009 @see mbrtowc()
       
  1010 @see printf()
       
  1011 @see strtod()
       
  1012 @see strtol()
       
  1013 @see strtoul()
       
  1014 @see wscanf()
       
  1015  
       
  1016 
       
  1017 @publishedAll
       
  1018 @externallyDefinedApi
       
  1019 */
       
  1020 
       
  1021 /** @fn  fseek(FILE *fp, long offset, int whence)
       
  1022 @param fp
       
  1023 @param offset
       
  1024 @param whence
       
  1025 
       
  1026 Note: This description also covers the following functions -
       
  1027  ftell()  rewind()  fgetpos()  fsetpos() 
       
  1028 
       
  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.
       
  1031 
       
  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.
       
  1039 
       
  1040 The ftell function obtains the current value of the file position indicator for the stream pointed to by fp.
       
  1041 
       
  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:
       
  1043 
       
  1044 @code
       
  1045      (void)fseek(fp, 0L, SEEK_SET)
       
  1046 
       
  1047 @endcode
       
  1048 
       
  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.
       
  1061 
       
  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.
       
  1070 
       
  1071 
       
  1072 Examples:
       
  1073 @code
       
  1074 /* this program shows setting file offset using fseek */
       
  1075 #include <stdio.h>
       
  1076 int main(void)
       
  1077 {       
       
  1078         int retval;
       
  1079         FILE *fp = NULL;
       
  1080         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  1081         	{
       
  1082         	printf("Failed to set text-mode\n");
       
  1083         	return -1;
       
  1084         	}
       
  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");
       
  1089         fclose(fp);
       
  1090         fp = fopen("c:\input.txt", "r");
       
  1091         if (fp == NULL)
       
  1092         {
       
  1093         printf ("fopen failed");
       
  1094         return -1;
       
  1095         }
       
  1096         retval = fseek(fp, 3, SEEK_SET); // seek to the 20th byte of the file
       
  1097         if (retval)
       
  1098         {
       
  1099         printf ("fseek failed");
       
  1100         return -1;
       
  1101         }
       
  1102         
       
  1103         long pos = ftell(fp);
       
  1104         if (pos ==3)
       
  1105         {       
       
  1106         printf("offset setting proper");
       
  1107         }
       
  1108         fclose(fp);
       
  1109         return 0;
       
  1110 }
       
  1111 
       
  1112 @endcode
       
  1113 @code
       
  1114 Output
       
  1115 
       
  1116 offset setting proper
       
  1117 
       
  1118 @endcode
       
  1119 
       
  1120 
       
  1121 
       
  1122 
       
  1123 @see lseek()
       
  1124 @see ungetc()
       
  1125 @see ungetwc()
       
  1126 @see set_fmode()
       
  1127  
       
  1128 
       
  1129 @publishedAll
       
  1130 @externallyDefinedApi
       
  1131 */
       
  1132 
       
  1133 /** @fn  fsetpos(FILE *iop, const fpos_t *pos)
       
  1134 @param iop
       
  1135 @param pos
       
  1136 
       
  1137 Refer to  fseek() for the documentation
       
  1138 @see lseek()
       
  1139 @see ungetc()
       
  1140 @see ungetwc()
       
  1141  
       
  1142 
       
  1143 @publishedAll
       
  1144 @externallyDefinedApi
       
  1145 */
       
  1146 
       
  1147 /** @fn  fsetpos64(FILE *iop, const fpos64_t *pos)
       
  1148 @param iop
       
  1149 @param pos
       
  1150 
       
  1151 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
       
  1152 
       
  1153 @see fsetpos()
       
  1154  
       
  1155 
       
  1156 @publishedAll
       
  1157 @externallyDefinedApi
       
  1158 */
       
  1159 
       
  1160 /** @fn  ftell(FILE *fp)
       
  1161 @param fp
       
  1162 
       
  1163 Refer to  fseek(), set_fmode() for the documentation
       
  1164 @see lseek()
       
  1165 @see ungetc()
       
  1166 @see ungetwc()
       
  1167 @see set_fmode()
       
  1168  
       
  1169 
       
  1170 @publishedAll
       
  1171 @externallyDefinedApi
       
  1172 */
       
  1173 
       
  1174 /** @fn  fwrite(const void *  buf, size_t size, size_t count, FILE *  fp)
       
  1175 @param buf
       
  1176 @param size
       
  1177 @param count
       
  1178 @param fp
       
  1179 
       
  1180 Refer to  fread() for the documentation
       
  1181 @see read()
       
  1182 @see write()
       
  1183  
       
  1184 
       
  1185 @publishedAll
       
  1186 @externallyDefinedApi
       
  1187 */
       
  1188 
       
  1189 /** @fn  getc(FILE *fp)
       
  1190 @param fp
       
  1191 
       
  1192 Refer to  fgetc() for the documentation
       
  1193 @see ferror()
       
  1194 @see flockfile()
       
  1195 @see fopen()
       
  1196 @see fread()
       
  1197 @see getwc()
       
  1198 @see putc()
       
  1199 @see ungetc()
       
  1200  
       
  1201 
       
  1202 @publishedAll
       
  1203 @externallyDefinedApi
       
  1204 */
       
  1205 
       
  1206 /** @fn  getchar()
       
  1207 @param 
       
  1208 
       
  1209 Refer to  fgetc() for the documentation
       
  1210 @see ferror()
       
  1211 @see flockfile()
       
  1212 @see fopen()
       
  1213 @see fread()
       
  1214 @see getwc()
       
  1215 @see putc()
       
  1216 @see ungetc()
       
  1217  
       
  1218 
       
  1219 @publishedAll
       
  1220 @externallyDefinedApi
       
  1221 */
       
  1222 
       
  1223 /** @fn  gets(char *str)
       
  1224 @param str
       
  1225 
       
  1226 Refer to  fgets() for the documentation
       
  1227 @see feof()
       
  1228 @see ferror()
       
  1229 @see fgetln()
       
  1230  
       
  1231 
       
  1232 @publishedAll
       
  1233 @externallyDefinedApi
       
  1234 */
       
  1235 
       
  1236 /** @fn  perror(const char *string)
       
  1237 @param string
       
  1238 
       
  1239 Note: This description also covers the following functions -
       
  1240  strerror()  strerror_r() 
       
  1241 
       
  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 
       
  1246   errno.
       
  1247 
       
  1248   The strerror , strerror_r and perror functions look up the error message string corresponding to an
       
  1249 error number.
       
  1250 
       
  1251  The strerror function accepts an error number argument errnum and returns a pointer to the corresponding
       
  1252 message string.
       
  1253 
       
  1254  The strerror_r function renders the same result into strerrbuf for a maximum of buflen characters and returns 0 upon success.
       
  1255 
       
  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.
       
  1264 
       
  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 .
       
  1271 
       
  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 .
       
  1274 
       
  1275  The message strings can be accessed directly using the external
       
  1276 array sys_errlist .
       
  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.
       
  1279 
       
  1280 Examples:
       
  1281 @code
       
  1282 #include <string.h>
       
  1283 #include <stdio.h>
       
  1284 #include <errno.h>
       
  1285 int main()
       
  1286 {
       
  1287     char *ptr = strerror(ERANGE);
       
  1288     printf("strerror(ERANGE) = %s",ptr);
       
  1289     return 0;
       
  1290 }
       
  1291 
       
  1292 @endcode
       
  1293 @code
       
  1294 Output
       
  1295 
       
  1296 strerror(ERANGE) = Numerical result out of range
       
  1297 
       
  1298 @endcode
       
  1299 @see intro()
       
  1300 
       
  1301 
       
  1302 Bugs:
       
  1303 
       
  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
       
  1306 inconsistently. 
       
  1307  
       
  1308 
       
  1309 @publishedAll
       
  1310 @externallyDefinedApi
       
  1311 */
       
  1312 
       
  1313 /** @fn  printf(const char *fmt, ...)
       
  1314 @param fmt
       
  1315 @param ...
       
  1316 
       
  1317 Note: This description also covers the following functions -
       
  1318  fprintf()  sprintf()  snprintf()  asprintf()  vprintf()  vfprintf()  vsprintf()  vsnprintf()  vasprintf() 
       
  1319 
       
  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.
       
  1328 
       
  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.
       
  1330 
       
  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.
       
  1332 
       
  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').
       
  1334 
       
  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.
       
  1336 
       
  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.
       
  1338 
       
  1339 The sprintf and vsprintf functions effectively assume an infinite size.
       
  1340 
       
  1341 @code
       
  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:
       
  1343 
       
  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:
       
  1355 
       
  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 *    
       
  1365 
       
  1366 
       
  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.
       
  1368 
       
  1369       The following length modifier is valid for the a, A, e, E, f, F, g, or G conversion:
       
  1370 
       
  1371       Modifier    a, A, e, E, f, F, g, G
       
  1372       l (ell)     double (ignored, same behavior as without it)
       
  1373       L           long double
       
  1374 
       
  1375 
       
  1376       The following length modifier is valid for the c or s conversion:
       
  1377 
       
  1378       Modifier    c         s
       
  1379       l (ell)     wint_t    wchar_t *
       
  1380 
       
  1381 
       
  1382     * A character that specifies the type of conversion to be applied. 
       
  1383 
       
  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.
       
  1385 @endcode
       
  1386 @code
       
  1387 The conversion specifiers and their meanings are:
       
  1388 diouxX
       
  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.
       
  1392 
       
  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.
       
  1397 
       
  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.
       
  1401 
       
  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.
       
  1405 
       
  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 '%%'.
       
  1410 
       
  1411 @endcode
       
  1412 
       
  1413 The decimal point character is defined in the program's locale (category LC_NUMERIC ).
       
  1414 
       
  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. 
       
  1416 
       
  1417 
       
  1418 
       
  1419 Examples:
       
  1420 
       
  1421  To print a date and time in the form "Sunday, July 3, 10:02",
       
  1422 where weekday and month are pointers to strings:
       
  1423 @code
       
  1424 #include <stdio.h>
       
  1425 fprintf(stdout, "%s, %s %d, %.2d:%.2d
       
  1426 ",
       
  1427         weekday, month, day, hour, min);
       
  1428 
       
  1429 @endcode
       
  1430  To print pi
       
  1431 to five decimal places:
       
  1432 @code
       
  1433 #include <math.h>
       
  1434 #include <stdio.h>
       
  1435 fprintf(stdout, "pi = %.5f
       
  1436 ", 4 * atan(1.0));
       
  1437 
       
  1438 @endcode
       
  1439  To allocate a 128 byte string and print into it:
       
  1440 @code
       
  1441 #include <stdio.h>
       
  1442 #include <stdlib.h>
       
  1443 #include <stdarg.h>
       
  1444 char *newfmt(const char *fmt, ...)
       
  1445 {
       
  1446         char *p;
       
  1447         va_list ap;
       
  1448         if ((p = malloc(128)) == NULL)
       
  1449                 return (NULL);
       
  1450         va_start(ap, fmt);
       
  1451         (void) vsnprintf(p, 128, fmt, ap);
       
  1452         va_end(ap);
       
  1453         return (p);
       
  1454 }
       
  1455 
       
  1456 @endcode
       
  1457 @code
       
  1458 /* this program shows printing onto the console using printf */
       
  1459 #include <stdio.h>
       
  1460 int main(void)
       
  1461 {
       
  1462         char * msg="hello world";
       
  1463         printf("%s",msg);
       
  1464         return 0;
       
  1465 }
       
  1466 
       
  1467 @endcode
       
  1468 @code
       
  1469 Output
       
  1470 
       
  1471 hello world
       
  1472 
       
  1473 @endcode
       
  1474 @code
       
  1475 /* this program shows reading from console using scanf */
       
  1476 #include <stdio.h>
       
  1477 int main(void)
       
  1478 {
       
  1479         char msg[100];
       
  1480         printf("enter message to be printed");
       
  1481         scanf("%s",msg);
       
  1482         printf("message entered is: %s",msg);
       
  1483         return 0;
       
  1484 }
       
  1485 
       
  1486 @endcode
       
  1487 @code
       
  1488 Output
       
  1489 
       
  1490 enter message to be printed
       
  1491 hello (assuming this is user input)
       
  1492 message entered is: hello
       
  1493 
       
  1494 @endcode
       
  1495 
       
  1496 Security considerations:
       
  1497 
       
  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.
       
  1505 
       
  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
       
  1512 addresses.
       
  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:
       
  1519 
       
  1520 @code     
       
  1521 snprintf(buffer, sizeof(buffer), "%s", string);
       
  1522 @endcode
       
  1523 @return   None of these functions support long double length modifiers. Floating point 
       
  1524 format specifiers support a maximum precision of 15 digits.
       
  1525 
       
  1526 @see printf()
       
  1527 @see scanf()
       
  1528 @see setlocale()
       
  1529 @see wprintf()
       
  1530 
       
  1531 
       
  1532 Bugs:
       
  1533 
       
  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. 
       
  1540  
       
  1541 
       
  1542 @publishedAll
       
  1543 @externallyDefinedApi
       
  1544 */
       
  1545 
       
  1546 /** @fn  putc(int c, FILE *fp)
       
  1547 @param c
       
  1548 @param fp
       
  1549 
       
  1550 Refer to  fputc() for the documentation
       
  1551 @see ferror()
       
  1552 @see flockfile()
       
  1553 @see fopen()
       
  1554 @see getc()
       
  1555 @see putwc()
       
  1556  
       
  1557 
       
  1558 @publishedAll
       
  1559 @externallyDefinedApi
       
  1560 */
       
  1561 
       
  1562 /** @fn  putchar(int c)
       
  1563 @param c
       
  1564 
       
  1565 Refer to  fputc() for the documentation
       
  1566 @see ferror()
       
  1567 @see flockfile()
       
  1568 @see fopen()
       
  1569 @see getc()
       
  1570 @see putwc()
       
  1571  
       
  1572 
       
  1573 @publishedAll
       
  1574 @externallyDefinedApi
       
  1575 */
       
  1576 
       
  1577 /** @fn  puts(const char *str)
       
  1578 @param str
       
  1579 
       
  1580 Refer to  fputs() for the documentation
       
  1581 @see ferror()
       
  1582 @see fputws()
       
  1583 @see putc()
       
  1584  
       
  1585 
       
  1586 @publishedAll
       
  1587 @externallyDefinedApi
       
  1588 */
       
  1589 
       
  1590 /** @fn  remove(const char *file)
       
  1591 @param 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.
       
  1594 
       
  1595   The remove function removes the file or directory specified by file.
       
  1596 
       
  1597  If file specifies a directory, remove (file); is the equivalent of rmdir (file); Otherwise, it is the equivalent of unlink (file);
       
  1598  
       
  1599 
       
  1600 Examples:
       
  1601 @code
       
  1602 /* this program shows deleting a file using remove */
       
  1603 #include <stdio.h>
       
  1604 int main()
       
  1605 {
       
  1606         char *name = "C:\input.txt";
       
  1607         FILE *fp = NULL;
       
  1608         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  1609         	{
       
  1610         	printf("Failed to set text-mode\n");
       
  1611         	return -1;
       
  1612         	}
       
  1613         fp = fopen(name, "w+");
       
  1614         if (fp == NULL)
       
  1615                 {
       
  1616                 printf ("fopen failed");
       
  1617                 return -1;
       
  1618                 }
       
  1619         fprintf(fp,"hello world");
       
  1620         fclose(fp);
       
  1621         
       
  1622         remove(name);
       
  1623         fp=fopen(name,"r");
       
  1624         if (fp == NULL)
       
  1625                 {
       
  1626                 printf ("file has been deleted already");
       
  1627                 }
       
  1628         else
       
  1629                 {
       
  1630                 printf("remove failed");
       
  1631                 return -1;
       
  1632                 }
       
  1633         
       
  1634         return 0;
       
  1635 }
       
  1636 
       
  1637 @endcode
       
  1638 @code
       
  1639 Output
       
  1640 
       
  1641 file has been deleted already
       
  1642 
       
  1643 @endcode
       
  1644 
       
  1645 Limitations:
       
  1646 
       
  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.
       
  1651 
       
  1652 @see rmdir()
       
  1653 @see unlink()
       
  1654 @see set_fmode()
       
  1655 
       
  1656 
       
  1657 @capability Deferred @ref RFs::RmDir(const TDesC16&)
       
  1658 
       
  1659 @publishedAll
       
  1660 @externallyDefinedApi
       
  1661 */
       
  1662 
       
  1663 /** @fn  rename(const char *oldpath, const char *newpath)
       
  1664 @param oldpath
       
  1665 @param 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
       
  1668 error.
       
  1669 
       
  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.
       
  1674 
       
  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.
       
  1678 
       
  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.
       
  1683 
       
  1684  Note:
       
  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.
       
  1687 
       
  1688 
       
  1689 
       
  1690  Limitations:
       
  1691 
       
  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.
       
  1698 
       
  1699 Examples:
       
  1700 @code
       
  1701 /*
       
  1702  * Detailed description: This sample code demonstrates usage of rename system call.
       
  1703  *
       
  1704  * Preconditions: Example.cfg file should be present in the current working directory.
       
  1705  */
       
  1706 #include <stdio.h>
       
  1707 int main()
       
  1708 {
       
  1709   if(rename("Example.txt" , "Example2.txt") < 0 )  {
       
  1710      printf("Failed to rename Example.txt");
       
  1711      return -1;
       
  1712   }
       
  1713   printf("Rename successful");
       
  1714   return 0;
       
  1715 }
       
  1716 
       
  1717 @endcode
       
  1718 @code
       
  1719 Output
       
  1720 
       
  1721 Rename successful
       
  1722 
       
  1723 @endcode
       
  1724 @see open()
       
  1725 @see symlink()
       
  1726 
       
  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&)
       
  1732 
       
  1733 @publishedAll
       
  1734 @externallyDefinedApi
       
  1735 */
       
  1736 
       
  1737 /** @fn  rewind(FILE *fp)
       
  1738 @param fp
       
  1739 
       
  1740 Refer to  fseek() for the documentation
       
  1741 @see lseek()
       
  1742 @see ungetc()
       
  1743 @see ungetwc()
       
  1744  
       
  1745 
       
  1746 @publishedAll
       
  1747 @externallyDefinedApi
       
  1748 */
       
  1749 
       
  1750 /** @fn  scanf(const char *  fmt, ...)
       
  1751 @param fmt
       
  1752 @param ...
       
  1753 
       
  1754 Note: This description also covers the following functions -
       
  1755  fscanf()  sscanf()  vscanf()  vsscanf()  vfscanf() 
       
  1756 
       
  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.
       
  1764 
       
  1765  
       
  1766 
       
  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).
       
  1769 
       
  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).
       
  1777   
       
  1778 
       
  1779 Examples:
       
  1780 @code
       
  1781 /* this program shows scanning from file using fscanf */
       
  1782 #include <stdio.h>
       
  1783 int main(void)
       
  1784 {
       
  1785         char x;
       
  1786         int ret;
       
  1787         char* filename="c:\ScanfTest1.txt";
       
  1788         FILE *fp = NULL;
       
  1789         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  1790         	{
       
  1791         	printf("Failed to set text-mode\n");
       
  1792         	return -1;
       
  1793         	}
       
  1794         fp=fopen(filename,"w");
       
  1795         fprintf(fp,"%s","abcdesdafg");
       
  1796         fclose(fp);
       
  1797         fp=fopen(filename,"r");
       
  1798         ret=fscanf(fp,"%c",&x;);
       
  1799         fclose(fp);
       
  1800         printf("fscanf returned:%c",x);
       
  1801         unlink(filename);
       
  1802         getchar();
       
  1803         if(ret!= 1)
       
  1804                 return -1;
       
  1805         else
       
  1806                 return 0;
       
  1807 }
       
  1808 
       
  1809 @endcode
       
  1810 @code
       
  1811 Output
       
  1812 
       
  1813 fscanf returned:a
       
  1814 
       
  1815 
       
  1816 @endcode
       
  1817 Examples:
       
  1818 @code
       
  1819 /* this program shows scanning from file using fscanf */
       
  1820 #include <stdio.h>
       
  1821 int main(void)
       
  1822 {
       
  1823         char x;
       
  1824         int ret;
       
  1825         char* filename="c:\ScanfTest1.txt";
       
  1826         FILE *fp = NULL;
       
  1827         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  1828         	{
       
  1829         	printf("Failed to set text-mode\n");
       
  1830         	return -1;
       
  1831         	}
       
  1832         fp=fopen(filename,"w");
       
  1833         fprintf(fp,"%s","abcdesdafg");
       
  1834         fclose(fp);
       
  1835         fp=fopen(filename,"r");
       
  1836         ret=fscanf(fp,"%c",&x;);
       
  1837         fclose(fp);
       
  1838         printf("fscanf returned:%c",x);
       
  1839         unlink(filename);
       
  1840         getchar();
       
  1841         if(ret!= 1)
       
  1842                 return -1;
       
  1843         else
       
  1844                 return 0;
       
  1845 }
       
  1846 
       
  1847 @endcode
       
  1848 @code
       
  1849 Output
       
  1850 
       
  1851 fscanf returned:a
       
  1852 
       
  1853 
       
  1854 @endcode
       
  1855 @return   None of these functions support long double data types.
       
  1856 
       
  1857 @see getc()
       
  1858 @see mbrtowc()
       
  1859 @see printf()
       
  1860 @see strtod()
       
  1861 @see strtol()
       
  1862 @see strtoul()
       
  1863 @see wscanf()
       
  1864 @see set_fmode() 
       
  1865 
       
  1866 @publishedAll
       
  1867 @externallyDefinedApi
       
  1868 */
       
  1869 
       
  1870 /** @fn  setbuf(FILE *  fp, char *  buf)
       
  1871 @param fp
       
  1872 @param buf
       
  1873 
       
  1874 Note: This description also covers the following functions -
       
  1875  setbuffer()  setlinebuf()  setvbuf() 
       
  1876 
       
  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.
       
  1878 
       
  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.
       
  1880 
       
  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:
       
  1882 
       
  1883 @code
       
  1884 _IONBF
       
  1885  	unbuffered
       
  1886 _IOLBF
       
  1887  	line buffered
       
  1888 _IOFBF
       
  1889  	fully buffered
       
  1890 @endcode
       
  1891 
       
  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.
       
  1893 
       
  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.
       
  1895 
       
  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
       
  1897 
       
  1898 @code
       
  1899      setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
       
  1900 @endcode
       
  1901 
       
  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:
       
  1903 @code
       
  1904      setvbuf(stream, (char *)NULL, _IOLBF, 0);
       
  1905 @endcode
       
  1906 
       
  1907 
       
  1908 Examples:
       
  1909 @code
       
  1910 /* this program shows setting up a buffer using setbuf * /
       
  1911 #include <stdio.h>
       
  1912 int main()
       
  1913 {
       
  1914         FILE *fp = NULL;
       
  1915         char FullBuf[100];
       
  1916         char msg[100];
       
  1917         char * rptr;
       
  1918         char name[20] = "c:\setbuf1.txt";
       
  1919         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  1920         	{
       
  1921         	printf("Failed to set text-mode\n");
       
  1922         	return -1;
       
  1923         	}
       
  1924         fp = fopen(name, "w+");
       
  1925         if (fp == NULL)
       
  1926                 {
       
  1927                 printf ("fopen failed");
       
  1928                 return -1;
       
  1929                 }
       
  1930         setbuf(fp, FullBuf);  // Fully buffered
       
  1931         if (ferror(fp))
       
  1932                 {
       
  1933                 printf ("setbuf failed");
       
  1934                 fclose(fp);
       
  1935                 unlink(name);
       
  1936                 return -1;
       
  1937                 }
       
  1938         fprintf(fp, "we are trying to buffer 20 characters at once ");
       
  1939         
       
  1940         fclose(fp);
       
  1941         fp=fopen(name,"r");
       
  1942         rptr = fgets(msg,100,fp);
       
  1943         if(rptr == NULL)
       
  1944                 {
       
  1945                 printf("fgets failed");
       
  1946                 fclose(fp);
       
  1947                 return -1;
       
  1948                 }
       
  1949         printf("file reading returned \"%s\",msg);
       
  1950         fclose(fp);
       
  1951         
       
  1952         unlink(name);
       
  1953         return 0;
       
  1954 }
       
  1955 
       
  1956 @endcode
       
  1957 @code
       
  1958 Output
       
  1959 
       
  1960 file reading returned "we are trying to buffer 20 characters at once"
       
  1961 
       
  1962 
       
  1963 @endcode
       
  1964 @see fopen()
       
  1965 @see fread()
       
  1966 @see malloc()
       
  1967 @see printf()
       
  1968 @see set_fmode() 
       
  1969 
       
  1970 @publishedAll
       
  1971 @externallyDefinedApi
       
  1972 */
       
  1973 
       
  1974 /** @fn  setvbuf(FILE * fp, char *  buf, int mode, size_t size)
       
  1975 @param fp
       
  1976 @param buf
       
  1977 @param mode
       
  1978 @param size
       
  1979 
       
  1980 Refer to  setbuf() for the documentation
       
  1981 @see fopen()
       
  1982 @see fread()
       
  1983 @see malloc()
       
  1984 @see printf()
       
  1985  
       
  1986 
       
  1987 @publishedAll
       
  1988 @externallyDefinedApi
       
  1989 */
       
  1990 
       
  1991 /** @fn  sprintf(char *  str, const char *  fmt, ...)
       
  1992 @param str
       
  1993 @param fmt
       
  1994 @param ...
       
  1995 
       
  1996 Refer to  printf() for the documentation
       
  1997 @see printf()
       
  1998 @see scanf()
       
  1999 @see setlocale()
       
  2000 @see wprintf()
       
  2001  
       
  2002 
       
  2003 @publishedAll
       
  2004 @externallyDefinedApi
       
  2005 */
       
  2006 
       
  2007 /** @fn  sscanf(const char *  str, const char * fmt, ...)
       
  2008 @param str
       
  2009 @param fmt
       
  2010 @param ...
       
  2011 
       
  2012 Refer to  scanf() for the documentation
       
  2013 @see getc()
       
  2014 @see mbrtowc()
       
  2015 @see printf()
       
  2016 @see strtod()
       
  2017 @see strtol()
       
  2018 @see strtoul()
       
  2019 @see wscanf()
       
  2020  
       
  2021 
       
  2022 @publishedAll
       
  2023 @externallyDefinedApi
       
  2024 */
       
  2025 
       
  2026 /** @fn  tmpfile(void)
       
  2027 
       
  2028 
       
  2029 Note: This description also covers the following functions -
       
  2030  tmpnam()  tempnam() 
       
  2031 
       
  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
       
  2036 on error.
       
  2037 
       
  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 .
       
  2046 
       
  2047 @code
       
  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.
       
  2051 @endcode
       
  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\>.
       
  2053 
       
  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.
       
  2058 
       
  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
       
  2062 temporary file.
       
  2063 
       
  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 .
       
  2067 
       
  2068 Examples:
       
  2069 @code
       
  2070 #include<stdio.h> //SEEK_SET, printf, tmpfile, FILE
       
  2071 #include<sys/stat.h> //S_IWUSR
       
  2072  
       
  2073 int main()
       
  2074 {
       
  2075 //create the tmp directory
       
  2076  mkdir("c:\tmp", S_IWUSR);
       
  2077  
       
  2078 //call tmpfile to create a tempory file
       
  2079  FILE* fp = tmpfile();
       
  2080  char buf[10];
       
  2081  
       
  2082  if(fp)
       
  2083  {
       
  2084      //write onto the file
       
  2085      fprintf(fp, "%s", "hello");
       
  2086      fflush(fp);
       
  2087   
       
  2088      //seek to the beginning of the file
       
  2089      fseek(fp, SEEK_SET, 0); //beg of the file
       
  2090   
       
  2091      //read from the file
       
  2092      fscanf(fp, "%s", buf);
       
  2093      fflush(fp);
       
  2094  
       
  2095      //close the file
       
  2096      fclose(fp);
       
  2097  }
       
  2098  
       
  2099  printf("buf read: %s", buf);
       
  2100  
       
  2101  return 0;
       
  2102 }
       
  2103 
       
  2104 @endcode
       
  2105 @code
       
  2106 Output
       
  2107 
       
  2108 buf read: hello
       
  2109 
       
  2110 @endcode
       
  2111 @code
       
  2112 #include<stdio.h> //tmpnam, printf, FILE
       
  2113 #include<sys/stat.h> //S_IWUSR
       
  2114 #include<errno.h> //errno
       
  2115   
       
  2116 int main()
       
  2117 {
       
  2118  //create a directory c:\system emp
       
  2119  mkdir("c:\system\temp", S_IWUSR);
       
  2120   
       
  2121  char buf[L_tmpnam];
       
  2122  char rbuf[10];
       
  2123   
       
  2124  //call tmpnam() to create a file
       
  2125  char *rval = tmpnam(buf);
       
  2126   
       
  2127  errno = 0;
       
  2128  //open the file with the name returned by tmpnam()
       
  2129  FILE *fp = fopen(buf, "w");
       
  2130   
       
  2131  if (fp == NULL)
       
  2132  {
       
  2133      printf("fopen of file returned by tmpnam() failed - errno %d ", errno);
       
  2134      return -1;
       
  2135  }
       
  2136     
       
  2137  if(fp)
       
  2138  {
       
  2139     fprintf(fp, "%s", "check");
       
  2140     fclose(fp);
       
  2141  }
       
  2142    
       
  2143  fp = fopen(buf, "r");
       
  2144   
       
  2145  if(fp)
       
  2146  {
       
  2147      fscanf(fp, "%s", rbuf);
       
  2148      fclose(fp);
       
  2149  }
       
  2150   
       
  2151  printf("read from file: %s", rbuf);
       
  2152  printf("argument buf: %s", buf);
       
  2153  printf("return value: %s", rval);
       
  2154   
       
  2155  return 0;
       
  2156 }
       
  2157 
       
  2158 @endcode
       
  2159 @code
       
  2160 Output
       
  2161 
       
  2162 read from file: check
       
  2163 argument buf: /System/temp/tmp.0.U9UPTx
       
  2164 return value: /System/temp/tmp.0.U9UPTx
       
  2165 
       
  2166 @endcode
       
  2167 
       
  2168 Limitations:
       
  2169 
       
  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. 
       
  2172 
       
  2173 @see mktemp()
       
  2174 
       
  2175 
       
  2176 
       
  2177 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
       
  2178 
       
  2179 @publishedAll
       
  2180 @externallyDefinedApi
       
  2181 */
       
  2182 
       
  2183 /** @fn  tmpfile64(void)
       
  2184 
       
  2185 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
       
  2186 
       
  2187 @see tmpfile()
       
  2188 
       
  2189 @publishedAll
       
  2190 @externallyDefinedApi
       
  2191 */
       
  2192 
       
  2193 /** @fn  tmpnam(char *str)
       
  2194 @param str
       
  2195 
       
  2196 Refer to  tmpfile() for the documentation
       
  2197 @see mktemp()
       
  2198 
       
  2199 
       
  2200 
       
  2201 @capability Deferred @ref RFs::MkDir(const TDesC16&)
       
  2202 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
       
  2203 
       
  2204 @publishedAll
       
  2205 @externallyDefinedApi
       
  2206 */
       
  2207 
       
  2208 /** @fn  ungetc(int c, FILE *fp)
       
  2209 @param c
       
  2210 @param 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.
       
  2215 
       
  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.
       
  2225 
       
  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.
       
  2229 
       
  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
       
  2235 the call.
       
  2236 
       
  2237 
       
  2238 Examples:
       
  2239 @code
       
  2240 /* this pushing character to file stream using ungetc */
       
  2241 #include <stdio.h>
       
  2242 int main(void)
       
  2243 {
       
  2244         int c;
       
  2245         FILE *fp = NULL;
       
  2246         if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  2247         	{
       
  2248         	printf("Failed to set text-mode\n");
       
  2249         	return -1;
       
  2250         	}
       
  2251         fp = fopen("c:\input.txt", "w");
       
  2252         fprintf(fp, "%s", "abcdefghijklmn");
       
  2253         fprintf(fp, "%c", '');
       
  2254         fprintf(fp, "%s", "fdsfdsafsdabcdefghijklmn");
       
  2255         fclose(fp);
       
  2256         char * name = "C:\input.txt";
       
  2257         fp = fopen(name, "w+");
       
  2258         if (fp == NULL)
       
  2259                 {
       
  2260                 printf ("fopen failed");
       
  2261                 return -1;
       
  2262                 }
       
  2263         if(ungetc('a',fp)!='a') printf("ungetc failed");
       
  2264         
       
  2265         fseek(fp,-1,SEEK_CUR);
       
  2266         c=getc(fp);
       
  2267         printf("character read from stream is \"%c\",c);
       
  2268         fclose(fp);
       
  2269 }
       
  2270 
       
  2271 @endcode
       
  2272 @code
       
  2273 Output
       
  2274 
       
  2275  character read from stream is "a"
       
  2276 
       
  2277 @endcode
       
  2278 @see fseek()
       
  2279 @see getc()
       
  2280 @see ungetwc()
       
  2281 @see set_fmode() 
       
  2282 
       
  2283 @publishedAll
       
  2284 @externallyDefinedApi
       
  2285 */
       
  2286 
       
  2287 /** @fn  vfprintf(FILE *fp, const char *fmt0, va_list ap)
       
  2288 @param fp
       
  2289 @param fmt0
       
  2290 @param ap
       
  2291 
       
  2292 Refer to  printf() for the documentation
       
  2293 @see printf()
       
  2294 @see scanf()
       
  2295 @see setlocale()
       
  2296 @see wprintf()
       
  2297  
       
  2298 
       
  2299 @publishedAll
       
  2300 @externallyDefinedApi
       
  2301 */
       
  2302 
       
  2303 /** @fn  vprintf(const char *  fmt, va_list ap)
       
  2304 @param fmt
       
  2305 @param ap
       
  2306 
       
  2307 Refer to  printf() for the documentation
       
  2308 @see printf()
       
  2309 @see scanf()
       
  2310 @see setlocale()
       
  2311 @see wprintf()
       
  2312  
       
  2313 
       
  2314 @publishedAll
       
  2315 @externallyDefinedApi
       
  2316 */
       
  2317 
       
  2318 /** @fn  vsprintf(char *  str, const char *fmt, va_list ap)
       
  2319 @param str
       
  2320 @param fmt
       
  2321 @param ap
       
  2322 
       
  2323 Refer to  printf() for the documentation
       
  2324 @see printf()
       
  2325 @see scanf()
       
  2326 @see setlocale()
       
  2327 @see wprintf()
       
  2328  
       
  2329 
       
  2330 @publishedAll
       
  2331 @externallyDefinedApi
       
  2332 */
       
  2333 
       
  2334 /** @fn  snprintf(char *  str, size_t n, const char *  fmt, ...)
       
  2335 @param str
       
  2336 @param n
       
  2337 @param fmt
       
  2338 @param ...
       
  2339 
       
  2340 Refer to  printf() for the documentation
       
  2341 @see printf()
       
  2342 @see scanf()
       
  2343 @see setlocale()
       
  2344 @see wprintf()
       
  2345  
       
  2346 
       
  2347 @publishedAll
       
  2348 @externallyDefinedApi
       
  2349 */
       
  2350 
       
  2351 /** @fn  vfscanf(FILE *  stream, const char *  format, va_list ap)
       
  2352 @param stream
       
  2353 @param format
       
  2354 @param ap
       
  2355 
       
  2356 Refer to  scanf() for the documentation
       
  2357 @see getc()
       
  2358 @see mbrtowc()
       
  2359 @see printf()
       
  2360 @see strtod()
       
  2361 @see strtol()
       
  2362 @see strtoul()
       
  2363 @see wscanf()
       
  2364  
       
  2365 
       
  2366 @publishedAll
       
  2367 @externallyDefinedApi
       
  2368 */
       
  2369 
       
  2370 /** @fn  vscanf(const char *fmt, va_list ap)
       
  2371 @param fmt
       
  2372 @param ap
       
  2373 
       
  2374 Refer to  scanf() for the documentation
       
  2375 @see getc()
       
  2376 @see mbrtowc()
       
  2377 @see printf()
       
  2378 @see strtod()
       
  2379 @see strtol()
       
  2380 @see strtoul()
       
  2381 @see wscanf()
       
  2382  
       
  2383 
       
  2384 @publishedAll
       
  2385 @externallyDefinedApi
       
  2386 */
       
  2387 
       
  2388 /** @fn  vsnprintf(char *  str, size_t n, const char *  fmt, va_list ap)
       
  2389 @param str
       
  2390 @param n
       
  2391 @param fmt
       
  2392 @param ap
       
  2393 
       
  2394 Refer to  printf() for the documentation
       
  2395 @see printf()
       
  2396 @see scanf()
       
  2397 @see setlocale()
       
  2398 @see wprintf()
       
  2399  
       
  2400 
       
  2401 @publishedAll
       
  2402 @externallyDefinedApi
       
  2403 */
       
  2404 
       
  2405 /** @fn  vsscanf(const char *  str, const char *  format, va_list ap)
       
  2406 @param str
       
  2407 @param format
       
  2408 @param ap
       
  2409 
       
  2410 Refer to  scanf() for the documentation
       
  2411 @see getc()
       
  2412 @see mbrtowc()
       
  2413 @see printf()
       
  2414 @see strtod()
       
  2415 @see strtol()
       
  2416 @see strtoul()
       
  2417 @see wscanf()
       
  2418  
       
  2419 
       
  2420 @publishedAll
       
  2421 @externallyDefinedApi
       
  2422 */
       
  2423 
       
  2424 /** @fn  fdopen(int fd, const char *mode)
       
  2425 @param fd
       
  2426 @param mode
       
  2427 
       
  2428 Refer to  fopen() for the documentation
       
  2429 @see open()
       
  2430 @see fclose()
       
  2431 @see fileno()
       
  2432 @see fseek()
       
  2433  
       
  2434 
       
  2435 @publishedAll
       
  2436 @externallyDefinedApi
       
  2437 */
       
  2438 
       
  2439 /** @fn  fileno(FILE *fp)
       
  2440 @param fp
       
  2441 
       
  2442 Refer to  clearerr() for the documentation
       
  2443 @see open()
       
  2444 @see flockfile()
       
  2445  
       
  2446 
       
  2447 @publishedAll
       
  2448 @externallyDefinedApi
       
  2449 */
       
  2450 
       
  2451 /** @fn  popen(const char *command, const char *mode)
       
  2452 @param command
       
  2453 @param mode
       
  2454 
       
  2455 Notes:
       
  2456 
       
  2457 1. This description also covers the pclose() function.
       
  2458 
       
  2459 2. When a child process created using popen() exits, the parent process receives a SIGCHLD signal.
       
  2460 
       
  2461 @return   The popen function returns NULL if the fork
       
  2462 or pipe calls fail,
       
  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
       
  2464 returns an error.
       
  2465 
       
  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.
       
  2470 
       
  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.
       
  2473 
       
  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.
       
  2479 
       
  2480  Note that output popen streams are fully buffered by default.
       
  2481 
       
  2482  The pclose function waits for the associated process to terminate
       
  2483 and returns the exit status of the command
       
  2484 as returned by
       
  2485 wait4.
       
  2486 
       
  2487 
       
  2488 
       
  2489 @see pipe()
       
  2490 @see fclose()
       
  2491 @see fflush()
       
  2492 @see fopen()
       
  2493 @see system()
       
  2494 
       
  2495 
       
  2496 Bugs:
       
  2497 
       
  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. 
       
  2508  
       
  2509 
       
  2510 @publishedAll
       
  2511 @externallyDefinedApi
       
  2512 */
       
  2513 
       
  2514 /** @fn popen3(const char *file, const char *cmd, char** envp, int fds[3])
       
  2515 
       
  2516 Open stdin, stdout, and stderr streams and start external executable.
       
  2517 
       
  2518 Note: When a child process created using popen3() exits, the parent process receives a SIGCHLD signal.
       
  2519 
       
  2520 @publishedAll
       
  2521 @externallyDefinedApi
       
  2522 */
       
  2523 
       
  2524 /** @fn  ftrylockfile(FILE *fp)
       
  2525 @param fp
       
  2526 
       
  2527 Refer to  flockfile() for the documentation
       
  2528 @see getc_unlocked()
       
  2529 @see putc_unlocked()
       
  2530  
       
  2531 
       
  2532 @publishedAll
       
  2533 @externallyDefinedApi
       
  2534 */
       
  2535 
       
  2536 /** @fn  flockfile(FILE *fp)
       
  2537 @param fp
       
  2538 
       
  2539 Note: This description also covers the following functions -
       
  2540  ftrylockfile()  funlockfile() 
       
  2541 
       
  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.
       
  2544 
       
  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.
       
  2549 
       
  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.
       
  2552 
       
  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.
       
  2554 
       
  2555  The funlockfile function releases the lock on a stream acquired by an earlier call to flockfile or ftrylockfile.
       
  2556 
       
  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.
       
  2561   
       
  2562   
       
  2563 Examples:
       
  2564 @code
       
  2565 #include <stdio.h>
       
  2566 #include <unistd.h>
       
  2567 #include <pthread.h> //link to the lib -libpthread
       
  2568  
       
  2569 void* somefun(void* args)
       
  2570 {
       
  2571 FILE *fp = (FILE *)args;
       
  2572 printf("in thr 2");
       
  2573 flockfile(fp);
       
  2574 printf("aquired lock!");
       
  2575 fputc('a', fp); //fputc_unlocked() is more relevant
       
  2576 printf("after a from thr 2");
       
  2577 sleep(3);
       
  2578 printf("after sleep from thr 2");
       
  2579 fputc('b', fp);
       
  2580 printf("after b from thr 2");
       
  2581 fputc('c', fp);
       
  2582 printf("after c from thr 2");
       
  2583 funlockfile(fp);
       
  2584 fclose(fp);
       
  2585 }
       
  2586 int main()
       
  2587 {
       
  2588 pthread_t obj;
       
  2589 FILE *fp = NULL;
       
  2590 if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  2591 	{
       
  2592     printf("Failed to set text-mode\n");
       
  2593     return -1;
       
  2594 	}
       
  2595 fp = fopen("c:\chk.txt", "w");
       
  2596 if(fp)
       
  2597 {
       
  2598         flockfile(fp);
       
  2599         fputc('x', fp); //fputc_unlocked() is more relevant
       
  2600         printf("after x from thr 1");
       
  2601         sleep(5);
       
  2602         printf("after sleep from thr 1");
       
  2603         pthread_create(&obj;, NULL, somefun, fp);
       
  2604         printf("after calling thr 2 from thr 1");
       
  2605         fputc('y', fp);
       
  2606         printf("after y from thr 1");
       
  2607         fputc('z', fp);
       
  2608         printf("after z from thr 1");
       
  2609         funlockfile(fp);
       
  2610         printf("gave up lock in thr 1");
       
  2611 }
       
  2612 pthread_exit((void *)0);
       
  2613 }
       
  2614 
       
  2615 @endcode
       
  2616 @code
       
  2617 Output
       
  2618 
       
  2619 after x from thr 1
       
  2620 after sleep from thr 1
       
  2621 in thr 2
       
  2622 after calling thr 2 from thr 1
       
  2623 after y from thr 1
       
  2624 after z from thr 1
       
  2625 gave up lock in thr 1
       
  2626 acquired lock!
       
  2627 after a from thr 2
       
  2628 after sleep from thr 2
       
  2629 after b from thr 2
       
  2630 after c from thr 2
       
  2631   
       
  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)
       
  2635  
       
  2636 
       
  2637 @endcode
       
  2638 @code
       
  2639 #include <stdio.h>
       
  2640 #include <unistd.h>
       
  2641 #include <pthread.h> //link to lib -libpthread
       
  2642 #include <errno.h>
       
  2643  
       
  2644 void* somefun(void* args)
       
  2645 {
       
  2646  
       
  2647 FILE *fp = (FILE *)args;
       
  2648  
       
  2649 printf("in thr 2
       
  2650 ");
       
  2651  
       
  2652 int i = ftrylockfile(fp);
       
  2653 if(i == 0)
       
  2654 {
       
  2655         printf("aquired lock!");
       
  2656         fputc('a', fp);
       
  2657         printf("after a from thr 2");
       
  2658         sleep(3);
       
  2659         printf("after sleep from thr 2");
       
  2660         fputc('b', fp);
       
  2661         printf("after b from thr 2");
       
  2662         fputc('c', fp);
       
  2663         printf("after c from thr 2");
       
  2664         funlockfile(fp);
       
  2665         printf("gave up lock in thr 2");
       
  2666 }
       
  2667 else
       
  2668         printf("couldn't aquire lock");
       
  2669 }
       
  2670 int main()
       
  2671 {
       
  2672 pthread_t obj;
       
  2673 FILE *fp = NULL;
       
  2674 if( set_fmode('t') != 0 )					// setting text-mode as default file opening mode throughtout the appln.
       
  2675 	{
       
  2676     printf("Failed to set text-mode\n");
       
  2677     return -1;
       
  2678 	}
       
  2679 fp = fopen("c:\chk.txt", "w");
       
  2680  
       
  2681 if(fp)
       
  2682 {
       
  2683         flockfile(fp);
       
  2684         fputc('x', fp);
       
  2685         printf("after x from thr 1");
       
  2686         sleep(5);
       
  2687         printf("after sleep from thr 1");
       
  2688         pthread_create(&obj;, NULL, somefun, fp);
       
  2689         printf("after calling thr 2 from thr 1");
       
  2690         fputc('y', fp);
       
  2691         printf("after y from thr 1");
       
  2692         fputc('z', fp);
       
  2693         printf("after z from thr 1");
       
  2694         funlockfile(fp);
       
  2695         printf("gave up lock in thr 1");
       
  2696         sleep(5);
       
  2697         fclose(fp);
       
  2698 }
       
  2699 pthread_exit((void *)0);
       
  2700 }
       
  2701 
       
  2702 @endcode
       
  2703 @code
       
  2704 Output
       
  2705 
       
  2706 after x from thr 1
       
  2707 after sleep from thr 1
       
  2708 in thr 2
       
  2709 couldn't acquire lock
       
  2710 after calling thr 2 from thr 1
       
  2711 after y from thr 1
       
  2712 after z from thr 1
       
  2713 gave up lock in thr 1
       
  2714   
       
  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)
       
  2718   
       
  2719 
       
  2720 @endcode
       
  2721 @see getc_unlocked()
       
  2722 @see putc_unlocked()
       
  2723 @see set_fmode() 
       
  2724 
       
  2725 @publishedAll
       
  2726 @externallyDefinedApi
       
  2727 */
       
  2728 
       
  2729 /** @fn  funlockfile(FILE *fp)
       
  2730 @param fp
       
  2731 
       
  2732 Refer to  flockfile() for the documentation
       
  2733 @see getc_unlocked()
       
  2734 @see putc_unlocked()
       
  2735  
       
  2736 
       
  2737 @publishedAll
       
  2738 @externallyDefinedApi
       
  2739 */
       
  2740 
       
  2741 /** @fn  getc_unlocked(FILE *fp)
       
  2742 @param fp
       
  2743 
       
  2744 Refer to  fgetc() for the documentation
       
  2745 @see ferror()
       
  2746 @see flockfile()
       
  2747 @see fopen()
       
  2748 @see fread()
       
  2749 @see getwc()
       
  2750 @see putc()
       
  2751 @see ungetc()
       
  2752  
       
  2753 
       
  2754 @publishedAll
       
  2755 @externallyDefinedApi
       
  2756 */
       
  2757 
       
  2758 /** @fn  getchar_unlocked(void)
       
  2759 
       
  2760 
       
  2761 Refer to  fgetc() for the documentation
       
  2762 @see ferror()
       
  2763 @see flockfile()
       
  2764 @see fopen()
       
  2765 @see fread()
       
  2766 @see getwc()
       
  2767 @see putc()
       
  2768 @see ungetc()
       
  2769  
       
  2770 
       
  2771 @publishedAll
       
  2772 @externallyDefinedApi
       
  2773 */
       
  2774 
       
  2775 /** @fn  putc_unlocked(int ch, FILE *fp)
       
  2776 @param ch
       
  2777 @param fp
       
  2778 
       
  2779 Refer to  fputc() for the documentation
       
  2780 @see ferror()
       
  2781 @see flockfile()
       
  2782 @see fopen()
       
  2783 @see getc()
       
  2784 @see putwc()
       
  2785  
       
  2786 
       
  2787 @publishedAll
       
  2788 @externallyDefinedApi
       
  2789 */
       
  2790 
       
  2791 /** @fn  putchar_unlocked(int ch)
       
  2792 @param ch
       
  2793 
       
  2794 Refer to  fputc() for the documentation
       
  2795 @see ferror()
       
  2796 @see flockfile()
       
  2797 @see fopen()
       
  2798 @see getc()
       
  2799 @see putwc()
       
  2800  
       
  2801 
       
  2802 @publishedAll
       
  2803 @externallyDefinedApi
       
  2804 */
       
  2805 
       
  2806 /** @fn  getw(FILE *fp)
       
  2807 @param fp
       
  2808 
       
  2809 Refer to  fgetc() for the documentation
       
  2810 @see ferror()
       
  2811 @see flockfile()
       
  2812 @see fopen()
       
  2813 @see fread()
       
  2814 @see getwc()
       
  2815 @see putc()
       
  2816 @see ungetc()
       
  2817  
       
  2818 
       
  2819 @publishedAll
       
  2820 @externallyDefinedApi
       
  2821 */
       
  2822 
       
  2823 /** @fn  putw(int w, FILE *fp)
       
  2824 @param w
       
  2825 @param fp
       
  2826 
       
  2827 Refer to  fputc() for the documentation
       
  2828 @see ferror()
       
  2829 @see flockfile()
       
  2830 @see fopen()
       
  2831 @see getc()
       
  2832 @see putwc()
       
  2833  
       
  2834 
       
  2835 @publishedAll
       
  2836 @externallyDefinedApi
       
  2837 */
       
  2838 
       
  2839 /** @fn tempnam(const char *, const char *)
       
  2840 Refer to tmpfile() for the documentation
       
  2841 @publishedAll
       
  2842 @externallyDefinedApi
       
  2843 */
       
  2844 
       
  2845 /** @fn  asprintf(char **str, const char *fmt, ...)
       
  2846 @param str
       
  2847 @param fmt
       
  2848 @param ...
       
  2849 
       
  2850 Refer to  printf() for the documentation
       
  2851 @see printf()
       
  2852 @see scanf()
       
  2853 @see setlocale()
       
  2854 @see wprintf()
       
  2855  
       
  2856 
       
  2857 @publishedAll
       
  2858 @externallyDefinedApi
       
  2859 */
       
  2860 
       
  2861 /** @fn  setbuffer(FILE *fp, char *buf, int size)
       
  2862 @param fp
       
  2863 @param buf
       
  2864 @param size
       
  2865 
       
  2866 Refer to  setbuf() for the documentation
       
  2867 @see fopen()
       
  2868 @see fread()
       
  2869 @see malloc()
       
  2870 @see printf()
       
  2871  
       
  2872 
       
  2873 @publishedAll
       
  2874 @externallyDefinedApi
       
  2875 */
       
  2876 
       
  2877 /** @fn  setlinebuf(FILE *fp)
       
  2878 @param fp
       
  2879 
       
  2880 Refer to  setbuf() for the documentation
       
  2881 @see fopen()
       
  2882 @see fread()
       
  2883 @see malloc()
       
  2884 @see printf()
       
  2885  
       
  2886 
       
  2887 @publishedAll
       
  2888 @externallyDefinedApi
       
  2889 */
       
  2890 
       
  2891 /** @fn  vasprintf(char **str, const char *fmt, va_list ap)
       
  2892 @param str
       
  2893 @param fmt
       
  2894 @param ap
       
  2895 
       
  2896 Refer to  printf() for the documentation
       
  2897 @see printf()
       
  2898 @see scanf()
       
  2899 @see setlocale()
       
  2900 @see wprintf()
       
  2901  
       
  2902 
       
  2903 @publishedAll
       
  2904 @externallyDefinedApi
       
  2905 */
       
  2906 
       
  2907 /** @fn  ftruncate(int fd, off_t length)
       
  2908 @param fd
       
  2909 @param length
       
  2910 
       
  2911 Refer to  truncate() for the documentation
       
  2912 @see open()
       
  2913  
       
  2914 
       
  2915 @publishedAll
       
  2916 @externallyDefinedApi
       
  2917 */
       
  2918 
       
  2919 /** @fn  lseek(int fildes, off_t offset, int whence)
       
  2920 @param fildes
       
  2921 @param offset
       
  2922 @param whence
       
  2923 @return   Upon successful completion, lseek returns the resulting offset location as measured in bytes from the
       
  2924 beginning of the file.
       
  2925 Otherwise,
       
  2926 a value of -1 is returned and errno is set to indicate
       
  2927 the error.
       
  2928 
       
  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:
       
  2931 @code
       
  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.
       
  2935 @endcode
       
  2936 Some devices are incapable of seeking. The value of the pointer associated with such a device is undefined.
       
  2937 
       
  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.
       
  2940 
       
  2941 
       
  2942 
       
  2943 Examples:
       
  2944 @code
       
  2945 /* Detailed description  : Example for lseek usage.*/
       
  2946 #include <stdio.h>
       
  2947 #include <sys/stat.h>
       
  2948 #include <fcntl.h>
       
  2949 #include <sys/types.h>
       
  2950 int main()
       
  2951 {
       
  2952 int fd = 0;
       
  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");
       
  2956       return -1;
       
  2957   }
       
  2958   printf("Lseek on lseek.txt passed ");
       
  2959  return 0;
       
  2960 }
       
  2961 
       
  2962 @endcode
       
  2963 @code
       
  2964 Output
       
  2965 
       
  2966 Lseek on lseek.txt passed
       
  2967 
       
  2968 @endcode
       
  2969 @see dup()
       
  2970 @see open()
       
  2971  
       
  2972 
       
  2973 @publishedAll
       
  2974 @externallyDefinedApi
       
  2975 */
       
  2976 
       
  2977 
       
  2978 /** @fn  truncate(const char *path, off_t length)
       
  2979 @param path
       
  2980 @param length
       
  2981 
       
  2982 Note: This description also covers the following functions -
       
  2983  ftruncate() 
       
  2984 
       
  2985 @return   Upon successful completion, both truncate() and ftruncate() return 0; otherwise, 
       
  2986 they return -1 and set errno to indicate the error.
       
  2987 
       
  2988   The truncate system call
       
  2989 causes the file named by path or referenced by fd to be truncated to length bytes in size.
       
  2990 If the file
       
  2991 was larger than this size, the extra data
       
  2992 is lost.
       
  2993 If the file was smaller than this size,
       
  2994 it will be extended as if by writing bytes with the value zero.
       
  2995 With ftruncate ,
       
  2996 the file must be open for writing.
       
  2997 
       
  2998 Examples:
       
  2999 @code
       
  3000 //example for truncate
       
  3001 #include<unistd.h>
       
  3002 #include<stdio.h>
       
  3003 #include <sys/stat.h>
       
  3004 int test_truncate()
       
  3005 {
       
  3006         int retVal, retVal2, retSize, retSize2;
       
  3007         struct stat buf;
       
  3008         ssize_t size;
       
  3009         char *buffer = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx";
       
  3010         int fp = open("c:	est.txt", O_RDWR|O_CREAT);
       
  3011         size = write(fp,buffer,50);
       
  3012         close(fp);
       
  3013         retVal2 = stat("c:	est.txt", &buf; );
       
  3014         if ( !retVal2 )
       
  3015         {
       
  3016         retSize = buf.st_size;
       
  3017         printf("Size before: %d", retSize);
       
  3018         retVal = truncate("c:	est.txt", retSize/2 );
       
  3019         }
       
  3020         else
       
  3021         {
       
  3022         printf("Failed");
       
  3023         }
       
  3024         retVal2 = stat( "c:	est.txt", &buf; );
       
  3025         if ( !retVal2 )
       
  3026                 {
       
  3027                 retSize2 = buf.st_size;
       
  3028                 if( retSize2 == (retSize/2 ) )
       
  3029                         {
       
  3030                         printf("Size after: %d", retSize2);
       
  3031                         printf("Truncate passed");
       
  3032                         return 0;
       
  3033                         }
       
  3034                 else
       
  3035                         {
       
  3036                         printf("Failed");
       
  3037                         return -1;
       
  3038                         }
       
  3039                 }
       
  3040         else
       
  3041                 {
       
  3042                 printf("Failed");
       
  3043                 return -1;
       
  3044                 }
       
  3045 }
       
  3046 
       
  3047 Output
       
  3048 Size before: 50
       
  3049 Size after: 25
       
  3050 Ttruncate Passed
       
  3051 @endcode
       
  3052 
       
  3053 @code
       
  3054 //example for ftruncate
       
  3055 #include<unistd.h>
       
  3056 #include<stdio.h>
       
  3057 int test_ftruncate()
       
  3058 {
       
  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;
       
  3062    struct stat buf;
       
  3063    if(fp != -1)
       
  3064    {
       
  3065      retVal2 = fstat( fp, &buf; );
       
  3066      if ( !retVal2 )
       
  3067      {
       
  3068         retSize = buf.st_size;
       
  3069         printf("Size before: %d", retSize);
       
  3070         retVal = ftruncate( fp, retSize/2 );
       
  3071         close(fp);
       
  3072      }
       
  3073      else
       
  3074      {
       
  3075         printf("Failed");
       
  3076      }
       
  3077      fp = open("c:	est.txt", O_RDONLY);
       
  3078      if((fp != -1) && (!retVal))
       
  3079      {
       
  3080         retVal2 = fstat( fp, &buf; );
       
  3081         if ( !retVal2 )
       
  3082         {
       
  3083           retSize2 = buf.st_size;
       
  3084           if( retSize2 == (retSize/2 ) )
       
  3085           {
       
  3086             printf("Size after: %d", retSize2);
       
  3087             printf("Ftruncate Passed");
       
  3088           }
       
  3089           else
       
  3090           {
       
  3091             printf("Failed");
       
  3092           }
       
  3093      }
       
  3094      else
       
  3095      {
       
  3096        printf("Failed");
       
  3097      }
       
  3098   }
       
  3099 }
       
  3100 
       
  3101 Output
       
  3102 Size before: 100
       
  3103 Size after: 50
       
  3104 Ftruncate Passed
       
  3105 
       
  3106 @endcode
       
  3107 @see open()
       
  3108 
       
  3109 
       
  3110 Bugs:
       
  3111 
       
  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. 
       
  3114  
       
  3115 
       
  3116 @publishedAll
       
  3117 @externallyDefinedApi
       
  3118 */
       
  3119 
       
  3120 /** @fn int setecho(int fd, uint8_t echoval)
       
  3121 @param fd
       
  3122 @param echoval
       
  3123 
       
  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.
       
  3129 
       
  3130 Notes:
       
  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.
       
  3136 
       
  3137 @return Upon successfull completion it returns 0, otherwise -1, setting the errno.
       
  3138 
       
  3139 @publishedAll
       
  3140 @externallyDefinedApi
       
  3141 */
       
  3142 
       
  3143 /** @def va_list
       
  3144 
       
  3145 The type va_list is defined for variables used to traverse the list.
       
  3146 
       
  3147 @publishedAll
       
  3148 @externallyDefinedApi
       
  3149 */
       
  3150 
       
  3151 /** @def vfscanf
       
  3152 
       
  3153 To be used for vfscanf(..)
       
  3154 
       
  3155 @publishedAll
       
  3156 @externallyDefinedApi
       
  3157 */
       
  3158 
       
  3159 /** @def __SNBF	
       
  3160 
       
  3161 unbuffered 
       
  3162 
       
  3163 @publishedAll
       
  3164 @externallyDefinedApi
       
  3165 */
       
  3166 
       
  3167 /** @def __SRD	
       
  3168 
       
  3169 OK to read
       
  3170 
       
  3171 @publishedAll
       
  3172 @externallyDefinedApi
       
  3173 */
       
  3174 
       
  3175 /** @def __SLBF	
       
  3176 
       
  3177 line buffered
       
  3178 
       
  3179 @publishedAll
       
  3180 @externallyDefinedApi
       
  3181 */
       
  3182 
       
  3183 /** @def __SWR	
       
  3184 
       
  3185 OK to write
       
  3186 
       
  3187 @publishedAll
       
  3188 @externallyDefinedApi
       
  3189 */
       
  3190 
       
  3191 /** @def __SRW	
       
  3192 
       
  3193 open for reading & writing
       
  3194 
       
  3195 @publishedAll
       
  3196 @externallyDefinedApi
       
  3197 */
       
  3198 
       
  3199 /** @def __SEOF	
       
  3200 
       
  3201 found EOF
       
  3202 
       
  3203 @publishedAll
       
  3204 @externallyDefinedApi
       
  3205 */
       
  3206 
       
  3207 /** @def __SERR	
       
  3208 
       
  3209 found error
       
  3210 
       
  3211 @publishedAll
       
  3212 @externallyDefinedApi
       
  3213 */
       
  3214 
       
  3215 /** @def __SMBF	
       
  3216 
       
  3217 _buf is from malloc
       
  3218 
       
  3219 @publishedAll
       
  3220 @externallyDefinedApi
       
  3221 */
       
  3222 
       
  3223 /** @def __SAPP	
       
  3224 
       
  3225 fdopen()ed in append mode
       
  3226 
       
  3227 @publishedAll
       
  3228 @externallyDefinedApi
       
  3229 */
       
  3230 
       
  3231 /** @def __SSTR	
       
  3232 
       
  3233 this is an sprintf or snprintf string 
       
  3234 
       
  3235 @publishedAll
       
  3236 @externallyDefinedApi
       
  3237 */
       
  3238 
       
  3239 /** @def __SOPT	
       
  3240 
       
  3241 do fseek() optimization
       
  3242 
       
  3243 @publishedAll
       
  3244 @externallyDefinedApi
       
  3245 */
       
  3246 
       
  3247 /** @def __SNPT	
       
  3248 
       
  3249 do not do fseek() optimization 
       
  3250 
       
  3251 @publishedAll
       
  3252 @externallyDefinedApi
       
  3253 */
       
  3254 
       
  3255 /** @def __SOFF	
       
  3256 
       
  3257 set iff _offset is in fact correct
       
  3258 
       
  3259 @publishedAll
       
  3260 @externallyDefinedApi
       
  3261 */
       
  3262 
       
  3263 /** @def __SMOD	
       
  3264 
       
  3265 true; fgetln modified _p text
       
  3266 
       
  3267 @publishedAll
       
  3268 @externallyDefinedApi
       
  3269 */
       
  3270 
       
  3271 /** @def __SALC	
       
  3272 
       
  3273 allocate string space dynamically
       
  3274 
       
  3275 @publishedAll
       
  3276 @externallyDefinedApi
       
  3277 */
       
  3278 
       
  3279 /** @def __SIGN	
       
  3280 
       
  3281 ignore this file in _fwalk
       
  3282 
       
  3283 @publishedAll
       
  3284 @externallyDefinedApi
       
  3285 */
       
  3286 
       
  3287 /** @def _IOFBF	
       
  3288 
       
  3289 setvbuf should set fully buffered
       
  3290 
       
  3291 @publishedAll
       
  3292 @externallyDefinedApi
       
  3293 */
       
  3294 
       
  3295 /** @def _IOLBF	
       
  3296 
       
  3297 setvbuf should set line buffered 
       
  3298 
       
  3299 @publishedAll
       
  3300 @externallyDefinedApi
       
  3301 */
       
  3302 
       
  3303 /** @def _IONBF	
       
  3304 
       
  3305 setvbuf should set unbuffered 
       
  3306 
       
  3307 @publishedAll
       
  3308 @externallyDefinedApi
       
  3309 */
       
  3310 
       
  3311 /** @def BUFSIZ	
       
  3312 
       
  3313 size of buffer used by setbuf 
       
  3314 
       
  3315 @publishedAll
       
  3316 @externallyDefinedApi
       
  3317 */
       
  3318 
       
  3319 /** @def EOF	
       
  3320 
       
  3321 End of file
       
  3322 
       
  3323 @publishedAll
       
  3324 @externallyDefinedApi
       
  3325 */
       
  3326 
       
  3327 /** @def FOPEN_MAX
       
  3328 
       
  3329 must be less than OPEN_MAX
       
  3330 
       
  3331 @publishedAll
       
  3332 @externallyDefinedApi
       
  3333 */
       
  3334 
       
  3335 /** @def FILENAME_MAX
       
  3336 
       
  3337 must be less than PATH_MAX 
       
  3338 
       
  3339 @publishedAll
       
  3340 @externallyDefinedApi
       
  3341 */
       
  3342 
       
  3343 /** @def SEEK_END
       
  3344 
       
  3345 set file offset to EOF plus offset
       
  3346 
       
  3347 @publishedAll
       
  3348 @externallyDefinedApi
       
  3349 */
       
  3350 
       
  3351 /** @def SEEK_CUR
       
  3352 
       
  3353 set file offset to current plus offset
       
  3354 
       
  3355 @publishedAll
       
  3356 @externallyDefinedApi
       
  3357 */
       
  3358 
       
  3359 /** @def SEEK_SET
       
  3360 
       
  3361 set file offset to offset
       
  3362 
       
  3363 @publishedAll
       
  3364 @externallyDefinedApi
       
  3365 */
       
  3366 
       
  3367 /** @def TMP_MAX
       
  3368 
       
  3369 temporary max value
       
  3370 
       
  3371 @publishedAll
       
  3372 @externallyDefinedApi
       
  3373 */
       
  3374 
       
  3375 /** @def L_tmpnam
       
  3376 
       
  3377 must be == PATH_MAX
       
  3378 
       
  3379 @publishedAll
       
  3380 @externallyDefinedApi
       
  3381 */
       
  3382 
       
  3383 /** @def stdin
       
  3384 
       
  3385 standard input variable
       
  3386 
       
  3387 @publishedAll
       
  3388 @externallyDefinedApi
       
  3389 */
       
  3390 
       
  3391 /** @def stdout
       
  3392 
       
  3393 standard output variable
       
  3394 
       
  3395 @publishedAll
       
  3396 @externallyDefinedApi
       
  3397 */
       
  3398 
       
  3399 /** @def stderr
       
  3400 
       
  3401 standard error variable
       
  3402 
       
  3403 @publishedAll
       
  3404 @externallyDefinedApi
       
  3405 */
       
  3406 
       
  3407 /** @def L_cuserid
       
  3408 
       
  3409 size for cuserid(3)
       
  3410 
       
  3411 @publishedAll
       
  3412 @externallyDefinedApi
       
  3413 */
       
  3414 
       
  3415 /** @def L_ctermid
       
  3416 
       
  3417 size for ctermid(3)
       
  3418 
       
  3419 @publishedAll
       
  3420 @externallyDefinedApi
       
  3421 */
       
  3422 
       
  3423 
       
  3424 /** @def __isthreaded
       
  3425 
       
  3426 defined to isthreaded()
       
  3427 
       
  3428 @publishedAll
       
  3429 @externallyDefinedApi
       
  3430 */
       
  3431 
       
  3432 /** @def feof(p)
       
  3433 
       
  3434 Functions defined in ANSI C standard.
       
  3435 
       
  3436 @publishedAll
       
  3437 @externallyDefinedApi
       
  3438 */
       
  3439 
       
  3440 /** @def ferror(p)
       
  3441 
       
  3442 Functions defined in ANSI C standard.
       
  3443 
       
  3444 @publishedAll
       
  3445 @externallyDefinedApi
       
  3446 */
       
  3447 
       
  3448 /** @def clearerr(p)
       
  3449 
       
  3450 Functions defined in ANSI C standard.
       
  3451 
       
  3452 @publishedAll
       
  3453 @externallyDefinedApi
       
  3454 */
       
  3455 
       
  3456 /** @def fileno(p)
       
  3457 
       
  3458 Functions defined in ANSI C standard.
       
  3459 
       
  3460 @publishedAll
       
  3461 @externallyDefinedApi
       
  3462 */
       
  3463 
       
  3464 /** @def getc(fp)
       
  3465 
       
  3466 Functions defined in ANSI C standard.
       
  3467 
       
  3468 @publishedAll
       
  3469 @externallyDefinedApi
       
  3470 */
       
  3471 
       
  3472 /** @def getchar()
       
  3473 
       
  3474 Defined to getc(stdin)
       
  3475 
       
  3476 @publishedAll
       
  3477 @externallyDefinedApi
       
  3478 */
       
  3479 
       
  3480 /** @def putchar(x)
       
  3481 
       
  3482 defined to putc(x,stdout)
       
  3483 
       
  3484 @publishedAll
       
  3485 @externallyDefinedApi
       
  3486 */
       
  3487 
       
  3488 /** @struct __sbuf
       
  3489 
       
  3490 stdio buffers 
       
  3491 
       
  3492 @publishedAll
       
  3493 @externallyDefinedApi
       
  3494 */
       
  3495 
       
  3496 /** @var __sbuf::_base
       
  3497 Pointer to the buffer
       
  3498 */
       
  3499 
       
  3500 /** @var __sbuf::_size
       
  3501 size of the buffer
       
  3502 */
       
  3503 
       
  3504 /** @struct __sFILE
       
  3505 
       
  3506 stdio state file variables.
       
  3507 
       
  3508 @publishedAll
       
  3509 @externallyDefinedApi
       
  3510 */
       
  3511 
       
  3512 /** @typedef  typedef __off_t fpos_t
       
  3513 
       
  3514 Represents file position
       
  3515 
       
  3516 @publishedAll
       
  3517 @externallyDefinedApi
       
  3518 */
       
  3519 
       
  3520 /** @typedef  typedef __off_t fpos64_t
       
  3521 
       
  3522 Represents large file position
       
  3523 
       
  3524 @publishedAll
       
  3525 @externallyDefinedApi
       
  3526 */
       
  3527 
       
  3528 /** @typedef  typedef	__size_t	size_t
       
  3529 
       
  3530 A type to define sizes of strings and memory blocks.
       
  3531 
       
  3532 @publishedAll
       
  3533 @externallyDefinedApi
       
  3534 */
       
  3535 
       
  3536 /** @typedef  typedef	__va_list	va_list
       
  3537 
       
  3538 A void pointer which can be interpreted as an argument list.
       
  3539 
       
  3540 @publishedAll
       
  3541 @externallyDefinedApi
       
  3542 */
       
  3543 
       
  3544 
       
  3545 /** @fn tmpdirname(void)
       
  3546 
       
  3547 @return Upon successful completion tmpdirname() will return the path of the private directory of that process.
       
  3548 
       
  3549 Note:String that the function will return is not to be modified.
       
  3550 
       
  3551 Examples:
       
  3552 
       
  3553 @code
       
  3554 
       
  3555 /* Illustrates how to use tmpdirname() API */
       
  3556 #include <stdio.h>
       
  3557 int main()
       
  3558 	{
       
  3559 	char *ptr;
       
  3560 	ptr=tmpdirname();
       
  3561 	printf("%s\n",ptr);
       
  3562 	return 0;	
       
  3563 	}
       
  3564 @endcode
       
  3565 
       
  3566 @publishedAll
       
  3567 @released
       
  3568 */
       
  3569 
       
  3570 /** @fn  set_fmode(char mode)
       
  3571 @param mode
       
  3572 @return  set_fmode() returns 0 on success, otherwise returns -1 with an errno set to EINVAL. 
       
  3573 
       
  3574 set_fmode(), get_fmode() are used to provide text-mode support.
       
  3575 
       
  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.
       
  3577 
       
  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.
       
  3581       
       
  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.
       
  3586 	   
       
  3587 Examples:
       
  3588 @code
       
  3589 /*
       
  3590  * Detailed description : To set the mode of a file to either text/binary explicitly
       
  3591  */
       
  3592 #include <stdio.h>
       
  3593 int main() 
       
  3594 {
       
  3595   int ret;
       
  3596   ret = set_fmode('t');	
       
  3597   if(ret != 0 ) 
       
  3598   {
       
  3599      printf("Failed to set text mode\n") ;
       
  3600      return -1 ;
       
  3601   }
       
  3602   printf("Successfully able to set text mode\n") ;
       
  3603   if (get_fmode() != 't')
       
  3604   {
       
  3605      printf("Failed to Retrieve file-mode\n") ;
       
  3606      return -1 ;      
       
  3607   }	
       
  3608   printf("Successfully able to Retrieve file-mode\n") ;
       
  3609   getchar();
       
  3610   return 0 ;
       
  3611 }
       
  3612 
       
  3613 @endcode
       
  3614 
       
  3615 @see get_fmode()
       
  3616 @see fopen()
       
  3617 @see fclose()
       
  3618 @see setvbuf()
       
  3619 @see ftell()
       
  3620 @see fseek()
       
  3621 @see fread()
       
  3622 @see fwrite()
       
  3623 @see fputs()
       
  3624 @see fputc()
       
  3625 @see fgets()
       
  3626 @see fgetc()
       
  3627 @see fprintf()
       
  3628 @see fscanf()
       
  3629 
       
  3630 @publishedAll
       
  3631 @externallyDefinedApi
       
  3632 */
       
  3633 
       
  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.
       
  3637 		   
       
  3638 Examples:
       
  3639 @code
       
  3640 /*
       
  3641  * Detailed description : To Retrieve the current mode of a file
       
  3642  */
       
  3643 #include <stdio.h>
       
  3644 int main() 
       
  3645 {
       
  3646   int ret;
       
  3647   ret = set_fmode('t');	
       
  3648   if(ret != 0 ) 
       
  3649   {
       
  3650      printf("Failed to set text mode\n") ;
       
  3651      return -1 ;
       
  3652   }
       
  3653   printf("Successfully able to set text mode\n") ;
       
  3654   if (get_fmode() != 't')
       
  3655   {
       
  3656      printf("Failed to Retrieve file-mode\n") ;
       
  3657      return -1 ;      
       
  3658   }	
       
  3659   printf("Successfully able to Retrieve file-mode\n") ;
       
  3660   getchar();
       
  3661   return 0 ;
       
  3662 }
       
  3663 
       
  3664 @endcode
       
  3665 
       
  3666 Examples:
       
  3667 @code
       
  3668 /*
       
  3669  * Detailed description : General example to illustrate set_fmode(), get_fmode()
       
  3670  */
       
  3671 #include <stdio.h>
       
  3672 int main()
       
  3673 {
       
  3674     char *data = "helloworld\nfine";
       
  3675     char *p = NULL;
       
  3676     int ret = 0;
       
  3677     FILE *fw = NULL, *fr = NULL;
       
  3678     
       
  3679     ret = set_fmode('t');                   			// To set text-mode using set_fmode()
       
  3680 	if(ret != 0 ) 
       
  3681 		{
       
  3682 		printf("Failed to set text mode") ;
       
  3683 		return -1 ;
       
  3684 		}
       
  3685 	if (get_fmode() != 't')
       
  3686 		{
       
  3687 		printf("Failed to Retrieve file-mode") ;
       
  3688 		return -1 ;      
       
  3689 		}	
       
  3690 
       
  3691     fw = fopen("c:\\temp_tc.txt", "w");
       
  3692     int count = fwrite(data, 1, strlen(data), fw);
       
  3693 	if(count != strlen(data))
       
  3694 		{
       
  3695 		printf("fwrite() failed\n");
       
  3696 		goto end;
       
  3697 		}
       
  3698     fclose(fw);
       
  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'
       
  3702 	if( !p )
       
  3703 		{
       
  3704 		printf("malloc() failed\n");
       
  3705 		goto end;
       
  3706 		}
       
  3707     char *retn = fgets(p, count, fr);
       
  3708     //ret = fread(p, 1, 11, fr);
       
  3709     if(strlen(p) != 11)
       
  3710         {
       
  3711         printf("1st read failed\n");
       
  3712         goto end;
       
  3713         }
       
  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);
       
  3718     if( ret != 4)
       
  3719         {
       
  3720         printf("Failed to read using fread()\n");
       
  3721         goto end;
       
  3722         }
       
  3723     p[count] = '\0';
       
  3724     pos = ftell(fr);                            		// 16 -> offset
       
  3725     printf("pos After 2nd read: %d\n", pos);
       
  3726     getchar();
       
  3727     count = fwrite(p, 1, strlen(p), fw);
       
  3728     if(count != strlen(p))
       
  3729         {
       
  3730         printf(" Failed to write onto another file\n");
       
  3731         getchar();
       
  3732         }
       
  3733     else
       
  3734         {
       
  3735         printf("Passed to write onto another file\n");
       
  3736         getchar();
       
  3737         }
       
  3738 	end: 
       
  3739 	if(p)
       
  3740 		{
       
  3741 		free(p);
       
  3742 		p = NULL;
       
  3743 		}
       
  3744 	if(fr)
       
  3745 		fclose(fr);
       
  3746 	if(fw)
       
  3747 		fclose(fw);
       
  3748     return 0;                                                   
       
  3749 } 
       
  3750 @endcode
       
  3751 
       
  3752 @code
       
  3753 
       
  3754 Output:
       
  3755 pos After 1st read: 12
       
  3756 pos After 2nd read: 20
       
  3757 Passed to write onto another file
       
  3758 
       
  3759 @endcode
       
  3760 
       
  3761 @see set_fmode()
       
  3762 
       
  3763 @publishedAll
       
  3764 @externallyDefinedApi
       
  3765 */