ICU 55.1 55.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ustdio.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1998-2014, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 *
9 * File ustdio.h
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 10/16/98 stephen Creation.
15 * 11/06/98 stephen Modified per code review.
16 * 03/12/99 stephen Modified for new C API.
17 * 07/19/99 stephen Minor doc update.
18 * 02/01/01 george Added sprintf & sscanf with all of its variants
19 ******************************************************************************
20 */
21
22 #ifndef USTDIO_H
23 #define USTDIO_H
24
25 #include <stdio.h>
26 #include <stdarg.h>
27
28 #include "unicode/utypes.h"
29 #include "unicode/ucnv.h"
30 #include "unicode/utrans.h"
31 #include "unicode/localpointer.h"
32 #include "unicode/unum.h"
33
34 #if !UCONFIG_NO_CONVERSION
35
36 /*
37 TODO
38 The following is a small list as to what is currently wrong/suggestions for
39 ustdio.
40
41 * Make sure that * in the scanf format specification works for all formats.
42 * Each UFILE takes up at least 2KB.
43 Look into adding setvbuf() for configurable buffers.
44 * This library does buffering. The OS should do this for us already. Check on
45 this, and remove it from this library, if this is the case. Double buffering
46 wastes a lot of time and space.
47 * Test stdin and stdout with the u_f* functions
48 * Testing should be done for reading and writing multi-byte encodings,
49 and make sure that a character that is contained across buffer boundries
50 works even for incomplete characters.
51 * Make sure that the last character is flushed when the file/string is closed.
52 * snprintf should follow the C99 standard for the return value, which is
53 return the number of characters (excluding the trailing '\0')
54 which would have been written to the destination string regardless
55 of available space. This is like pre-flighting.
56 * Everything that uses %s should do what operator>> does for UnicodeString.
57 It should convert one byte at a time, and once a character is
58 converted then check to see if it's whitespace or in the scanset.
59 If it's whitespace or in the scanset, put all the bytes back (do nothing
60 for sprintf/sscanf).
61 * If bad string data is encountered, make sure that the function fails
62 without memory leaks and the unconvertable characters are valid
63 substitution or are escaped characters.
64 * u_fungetc() can't unget a character when it's at the beginning of the
65 internal conversion buffer. For example, read the buffer size # of
66 characters, and then ungetc to get the previous character that was
67 at the end of the last buffer.
68 * u_fflush() and u_fclose should return an int32_t like C99 functions.
69 0 is returned if the operation was successful and EOF otherwise.
70 * u_fsettransliterator does not support U_READ side of transliteration.
71 * The format specifier should limit the size of a format or honor it in
72 order to prevent buffer overruns. (e.g. %256.256d).
73 * u_fread and u_fwrite don't exist. They're needed for reading and writing
74 data structures without any conversion.
75 * u_file_read and u_file_write are used for writing strings. u_fgets and
76 u_fputs or u_fread and u_fwrite should be used to do this.
77 * The width parameter for all scanf formats, including scanset, needs
78 better testing. This prevents buffer overflows.
79 * Figure out what is suppose to happen when a codepage is changed midstream.
80 Maybe a flush or a rewind are good enough.
81 * Make sure that a UFile opened with "rw" can be used after using
82 u_fflush with a u_frewind.
83 * scanf(%i) should detect what type of number to use.
84 * Add more testing of the alternate format, %#
85 * Look at newline handling of fputs/puts
86 * Think more about codeunit/codepoint error handling/support in %S,%s,%C,%c,%[]
87 * Complete the file documentation with proper doxygen formatting.
88 See http://oss.software.ibm.com/pipermail/icu/2003-July/005647.html
89 */
90
207 #define U_EOF 0xFFFF
208
210 typedef struct UFILE UFILE;
211
217 typedef enum {
218 U_READ = 1,
219 U_WRITE = 2,
220 U_READWRITE =3 /* == (U_READ | U_WRITE) */
221 } UFileDirection;
222
240 U_STABLE UFILE* U_EXPORT2
241 u_fopen(const char *filename,
242 const char *perm,
243 const char *locale,
244 const char *codepage);
245
246 #ifndef U_HIDE_DRAFT_API
247
264 U_DRAFT UFILE* U_EXPORT2
265 u_fopen_u(const UChar *filename,
266 const char *perm,
267 const char *locale,
268 const char *codepage);
269 #endif /* U_HIDE_DRAFT_API */
270
287 U_STABLE UFILE* U_EXPORT2
288 u_finit(FILE *f,
289 const char *locale,
290 const char *codepage);
291
308 U_STABLE UFILE* U_EXPORT2
309 u_fadopt(FILE *f,
310 const char *locale,
311 const char *codepage);
312
327 U_STABLE UFILE* U_EXPORT2
328 u_fstropen(UChar *stringBuf,
329 int32_t capacity,
330 const char *locale);
331
338 U_STABLE void U_EXPORT2
339 u_fclose(UFILE *file);
340
341 #if U_SHOW_CPLUSPLUS_API
342
343 U_NAMESPACE_BEGIN
344
354 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFILEPointer, UFILE, u_fclose);
355
356 U_NAMESPACE_END
357
358 #endif
359
368 U_STABLE UBool U_EXPORT2
369 u_feof(UFILE *f);
370
381 U_STABLE void U_EXPORT2
382 u_fflush(UFILE *file);
383
389 U_STABLE void
390 u_frewind(UFILE *file);
391
398 U_STABLE FILE* U_EXPORT2
399 u_fgetfile(UFILE *f);
400
401 #if !UCONFIG_NO_FORMATTING
402
411 U_STABLE const char* U_EXPORT2
412 u_fgetlocale(UFILE *file);
413
422 U_STABLE int32_t U_EXPORT2
423 u_fsetlocale(UFILE *file,
424 const char *locale);
425
426 #endif
427
437 U_STABLE const char* U_EXPORT2
438 u_fgetcodepage(UFILE *file);
439
455 U_STABLE int32_t U_EXPORT2
456 u_fsetcodepage(const char *codepage,
457 UFILE *file);
458
459
466 U_STABLE UConverter* U_EXPORT2 u_fgetConverter(UFILE *f);
467
468 #if !UCONFIG_NO_FORMATTING
469
475 U_STABLE const UNumberFormat* U_EXPORT2 u_fgetNumberFormat(UFILE *f);
476
477 /* Output functions */
478
486 U_STABLE int32_t U_EXPORT2
487 u_printf(const char *patternSpecification,
488 ... );
489
498 U_STABLE int32_t U_EXPORT2
499 u_fprintf(UFILE *f,
500 const char *patternSpecification,
501 ... );
502
515 U_STABLE int32_t U_EXPORT2
516 u_vfprintf(UFILE *f,
517 const char *patternSpecification,
518 va_list ap);
519
527 U_STABLE int32_t U_EXPORT2
528 u_printf_u(const UChar *patternSpecification,
529 ... );
530
536 U_STABLE UFILE * U_EXPORT2
537 u_get_stdout(void);
538
547 U_STABLE int32_t U_EXPORT2
548 u_fprintf_u(UFILE *f,
549 const UChar *patternSpecification,
550 ... );
551
564 U_STABLE int32_t U_EXPORT2
565 u_vfprintf_u(UFILE *f,
566 const UChar *patternSpecification,
567 va_list ap);
568 #endif
569
579 U_STABLE int32_t U_EXPORT2
580 u_fputs(const UChar *s,
581 UFILE *f);
582
590 U_STABLE UChar32 U_EXPORT2
591 u_fputc(UChar32 uc,
592 UFILE *f);
593
605 U_STABLE int32_t U_EXPORT2
606 u_file_write(const UChar *ustring,
607 int32_t count,
608 UFILE *f);
609
610
611 /* Input functions */
612 #if !UCONFIG_NO_FORMATTING
613
623 U_STABLE int32_t U_EXPORT2
624 u_fscanf(UFILE *f,
625 const char *patternSpecification,
626 ... );
627
641 U_STABLE int32_t U_EXPORT2
642 u_vfscanf(UFILE *f,
643 const char *patternSpecification,
644 va_list ap);
645
655 U_STABLE int32_t U_EXPORT2
656 u_fscanf_u(UFILE *f,
657 const UChar *patternSpecification,
658 ... );
659
673 U_STABLE int32_t U_EXPORT2
674 u_vfscanf_u(UFILE *f,
675 const UChar *patternSpecification,
676 va_list ap);
677 #endif
678
691 U_STABLE UChar* U_EXPORT2
692 u_fgets(UChar *s,
693 int32_t n,
694 UFILE *f);
695
705 U_STABLE UChar U_EXPORT2
706 u_fgetc(UFILE *f);
707
718 U_STABLE UChar32 U_EXPORT2
719 u_fgetcx(UFILE *f);
720
732 U_STABLE UChar32 U_EXPORT2
733 u_fungetc(UChar32 c,
734 UFILE *f);
735
746 U_STABLE int32_t U_EXPORT2
747 u_file_read(UChar *chars,
748 int32_t count,
749 UFILE *f);
750
751 #if !UCONFIG_NO_TRANSLITERATION
752
770 U_STABLE UTransliterator* U_EXPORT2
771 u_fsettransliterator(UFILE *file, UFileDirection direction,
772 UTransliterator *adopt, UErrorCode *status);
773
774 #endif
775
776
777 /* Output string functions */
778 #if !UCONFIG_NO_FORMATTING
779
780
791 U_STABLE int32_t U_EXPORT2
792 u_sprintf(UChar *buffer,
793 const char *patternSpecification,
794 ... );
795
813 U_STABLE int32_t U_EXPORT2
814 u_snprintf(UChar *buffer,
815 int32_t count,
816 const char *patternSpecification,
817 ... );
818
832 U_STABLE int32_t U_EXPORT2
833 u_vsprintf(UChar *buffer,
834 const char *patternSpecification,
835 va_list ap);
836
857 U_STABLE int32_t U_EXPORT2
858 u_vsnprintf(UChar *buffer,
859 int32_t count,
860 const char *patternSpecification,
861 va_list ap);
862
872 U_STABLE int32_t U_EXPORT2
873 u_sprintf_u(UChar *buffer,
874 const UChar *patternSpecification,
875 ... );
876
893 U_STABLE int32_t U_EXPORT2
894 u_snprintf_u(UChar *buffer,
895 int32_t count,
896 const UChar *patternSpecification,
897 ... );
898
912 U_STABLE int32_t U_EXPORT2
913 u_vsprintf_u(UChar *buffer,
914 const UChar *patternSpecification,
915 va_list ap);
916
937 U_STABLE int32_t U_EXPORT2
938 u_vsnprintf_u(UChar *buffer,
939 int32_t count,
940 const UChar *patternSpecification,
941 va_list ap);
942
943 /* Input string functions */
944
955 U_STABLE int32_t U_EXPORT2
956 u_sscanf(const UChar *buffer,
957 const char *patternSpecification,
958 ... );
959
974 U_STABLE int32_t U_EXPORT2
975 u_vsscanf(const UChar *buffer,
976 const char *patternSpecification,
977 va_list ap);
978
989 U_STABLE int32_t U_EXPORT2
990 u_sscanf_u(const UChar *buffer,
991 const UChar *patternSpecification,
992 ... );
993
1008 U_STABLE int32_t U_EXPORT2
1009 u_vsscanf_u(const UChar *buffer,
1010 const UChar *patternSpecification,
1011 va_list ap);
1012
1013
1014 #endif
1015 #endif
1016 #endif
1017
1018