3 //=============================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Jesper S. M|ller<stophph@diku.dk>
9 * @author and a cast of thousands...
11 //=============================================================================
13 #ifndef ACE_OS_NS_STDIO_H
14 # define ACE_OS_NS_STDIO_H
16 # include /**/ "ace/pre.h"
18 # include "ace/config-all.h"
20 # if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/os_include/os_stdio.h"
25 #include "ace/os_include/os_fcntl.h"
26 #include "ace/os_include/os_inttypes.h"
27 #include "ace/os_include/os_errno.h"
28 #include /**/ "ace/ACE_export.h"
30 #if defined (CYGWIN32)
31 # include "ace/os_include/os_unistd.h"
34 #if defined (ACE_WIN32)
38 #if defined (ACE_EXPORT_MACRO)
39 # undef ACE_EXPORT_MACRO
41 #define ACE_EXPORT_MACRO ACE_Export
44 * We inline and undef some functions that may be implemented
45 * as macros on some platforms. This way macro definitions will
46 * be usable later as there is no way to save the macro definition
47 * using the pre-processor.
49 inline int ace_fgetc_helper (FILE *fp
)
56 #endif /* defined (fgetc) */
59 #if !defined (ACE_LACKS_FPUTC)
60 inline int ace_fputc_helper (int ch
, FILE *fp
)
63 return fputc (ch
, fp
);
66 return ::fputc (ch
, fp
);
67 #endif /* defined (fputc) */
69 #endif /* !ACE_LACKS_FPUTC */
71 #if !defined (ACE_LACKS_GETC)
72 inline int ace_getc_helper (FILE *fp
)
79 #endif /* defined (getc) */
83 #endif /* !ACE_LACKS_GETC */
85 inline int ace_putc_helper (int ch
, FILE *fp
)
90 #elif !defined (ACE_LACKS_PUTC)
91 return ::putc (ch
, fp
);
96 #endif /* defined (putc) */
99 #if !defined ACE_FILENO_EQUIVALENT
100 inline ACE_HANDLE
ace_fileno_helper (FILE *fp
)
102 # if defined (fileno)
103 return (ACE_HANDLE
)fileno (fp
);
105 # elif defined (ACE_LACKS_FILENO)
107 ACE_NOTSUP_RETURN (ACE_INVALID_HANDLE
);
109 return (ACE_HANDLE
)(intptr_t)ACE_STD_NAMESPACE::fileno (fp
);
110 # endif /* defined (fileno) */
112 #endif /* !ACE_FILENO_EQUIVALENT */
114 #if !defined (ACE_LACKS_CUSERID) && !defined(ACE_HAS_ALT_CUSERID) \
115 && !defined(ACE_WIN32) && !defined (ACE_VXWORKS)
116 /// Helper for the ACE_OS::cuserid() function
118 * On some platforms cuserid is a macro. Defining ACE_OS::cuserid()
119 * becomes really hard, as there is no way to save the macro
120 * definition using the pre-processor.
121 * This inline function achieves the same effect, without namespace
122 * pollution or performance penalties.
124 * @todo We maybe should move a lot of the code in ACE_OS::cuserid here so
125 * it is treated the same as the above ace_difftime and ace_timezone.
126 * But since there is a good deal more code in ACE_OS::cuserid, we
127 * probably need to move some of it off into some sort of emulation
130 inline char *ace_cuserid(char *user
)
132 return cuserid(user
);
134 #endif /* !ACE_LACKS_CUSERID && !ACE_HAS_ALT_CUSERID && ... */
136 # if defined (ACE_LACKS_FILELOCKS)
137 # if ! defined (ACE_VXWORKS) && !defined (INTEGRITY)
138 // VxWorks defines struct flock in sys/fcntlcom.h. But it doesn't
139 // appear to support flock ().
145 ACE_OFF_T l_len
; /* len == 0 means until end of file */
148 long l_pad
[4]; /* reserve area */
150 # endif /* ! VXWORKS */
151 # endif /* ACE_LACKS_FILELOCKS */
153 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
159 * @brief OS file locking structure.
161 class ACE_Export ace_flock_t
164 /// Dump state of the object.
167 # if defined (ACE_WIN32)
168 ACE_OVERLAPPED overlapped_
;
171 # endif /* ACE_WIN32 */
173 /// Name of this filelock.
174 const ACE_TCHAR
*lockname_
;
176 /// Handle to the underlying file.
180 # if defined (ACE_USES_WCHAR)
181 // If fp points to the Unicode format file, the file pointer will be moved right next
182 // to the Unicode header (2 types). Otherwise, file pointer will be at the beginning.
184 void checkUnicodeFormat (FILE* fp
);
185 # endif // ACE_USES_WCHAR
187 ACE_NAMESPACE_INLINE_FUNCTION
188 void clearerr (FILE* fp
);
190 //@{ @name Wrappers to obtain the current user id
191 // Legacy as per SUSV3
192 # if !defined (ACE_LACKS_CUSERID)
193 # if defined(cuserid)
195 # endif /* cuserid */
197 ACE_NAMESPACE_INLINE_FUNCTION
198 char *cuserid (char *user
,
199 size_t maxlen
= ACE_MAX_USERID
);
201 # if defined (ACE_HAS_WCHAR)
202 ACE_NAMESPACE_INLINE_FUNCTION
203 wchar_t *cuserid (wchar_t *user
,
204 size_t maxlen
= ACE_MAX_USERID
);
205 # endif /* ACE_HAS_WCHAR */
206 # endif /* ACE_LACKS_CUSERID */
210 int asprintf (char **bufp
, const char* format
, ...)
211 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 2, 3);
213 # if defined (ACE_HAS_WCHAR)
215 int asprintf (wchar_t **bufp
, const wchar_t* format
, ...);
216 #endif /* ACE_HAS_WCHAR */
218 ACE_NAMESPACE_INLINE_FUNCTION
219 int fclose (FILE *fp
);
221 ACE_NAMESPACE_INLINE_FUNCTION
222 FILE *fdopen (ACE_HANDLE handle
, const ACE_TCHAR
*mode
);
224 ACE_NAMESPACE_INLINE_FUNCTION
225 int fflush (FILE *fp
);
227 ACE_NAMESPACE_INLINE_FUNCTION
228 int fgetc (FILE* fp
);
230 ACE_NAMESPACE_INLINE_FUNCTION
233 ACE_NAMESPACE_INLINE_FUNCTION
234 int fgetpos (FILE* fp
, fpos_t* pos
);
236 ACE_NAMESPACE_INLINE_FUNCTION
237 char *fgets (char *buf
, int size
, FILE *fp
);
239 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FGETWS)
240 ACE_NAMESPACE_INLINE_FUNCTION
241 wchar_t *fgets (wchar_t *buf
, int size
, FILE *fp
);
242 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FGETWS */
244 //@{ @name A set of wrappers for file locks.
246 # if defined (ACE_WIN32)
247 ACE_NAMESPACE_INLINE_FUNCTION
248 void flock_adjust_params (ace_flock_t
*lock
,
252 # endif /* ACE_WIN32 */
254 ACE_NAMESPACE_INLINE_FUNCTION
255 int flock_init (ace_flock_t
*lock
,
257 const ACE_TCHAR
*name
= 0,
260 ACE_NAMESPACE_INLINE_FUNCTION
261 int flock_destroy (ace_flock_t
*lock
,
262 int unlink_file
= 1);
264 ACE_NAMESPACE_INLINE_FUNCTION
265 int flock_rdlock (ace_flock_t
*lock
,
270 ACE_NAMESPACE_INLINE_FUNCTION
271 int flock_tryrdlock (ace_flock_t
*lock
,
276 ACE_NAMESPACE_INLINE_FUNCTION
277 int flock_trywrlock (ace_flock_t
*lock
,
282 ACE_NAMESPACE_INLINE_FUNCTION
283 int flock_unlock (ace_flock_t
*lock
,
288 ACE_NAMESPACE_INLINE_FUNCTION
289 int flock_wrlock (ace_flock_t
*lock
,
297 ACE_NAMESPACE_INLINE_FUNCTION
298 ACE_HANDLE
fileno (FILE *stream
);
300 #if defined (ACE_WIN32)
303 ACE_NAMESPACE_INLINE_FUNCTION
304 #endif /* ACE_WIN32 */
305 FILE *fopen (const char *filename
, const char *mode
);
307 #if defined (ACE_HAS_WCHAR)
308 #if defined (ACE_WIN32)
311 ACE_NAMESPACE_INLINE_FUNCTION
312 #endif /* ACE_WIN32 */
313 FILE *fopen (const char *filename
, const wchar_t *mode
);
314 # if defined (ACE_WIN32)
317 ACE_NAMESPACE_INLINE_FUNCTION
318 # endif /* ACE_WIN32 */
319 FILE *fopen (const wchar_t *filename
, const wchar_t *mode
);
320 # if defined (ACE_WIN32)
323 ACE_NAMESPACE_INLINE_FUNCTION
324 # endif /* ACE_WIN32 */
325 FILE *fopen (const wchar_t *filename
, const char *mode
);
326 #endif /* ACE_HAS_WCHAR */
328 #if defined (ACE_WIN32)
329 /// Default Win32 Security Attributes definition.
330 ACE_NAMESPACE_INLINE_FUNCTION
331 LPSECURITY_ATTRIBUTES
default_win32_security_attributes (LPSECURITY_ATTRIBUTES
);
332 ACE_NAMESPACE_INLINE_FUNCTION
333 LPSECURITY_ATTRIBUTES
default_win32_security_attributes_r (LPSECURITY_ATTRIBUTES
,
334 LPSECURITY_ATTRIBUTES
,
335 SECURITY_DESCRIPTOR
*);
337 // = Win32 OS version determination function.
338 /// Return the win32 OSVERSIONINFO structure.
339 ACE_NAMESPACE_INLINE_FUNCTION
340 const ACE_TEXT_OSVERSIONINFO
&get_win32_versioninfo ();
342 // = A pair of functions for modifying ACE's Win32 resource usage.
343 /// Return the handle of the module containing ACE's resources. By
344 /// default, for a DLL build of ACE this is a handle to the ACE DLL
345 /// itself, and for a static build it is a handle to the executable.
346 ACE_NAMESPACE_INLINE_FUNCTION
347 HINSTANCE
get_win32_resource_module ();
349 /// Allow an application to modify which module contains ACE's
350 /// resources. This is mainly useful for a static build of ACE where
351 /// the required resources reside somewhere other than the executable.
352 ACE_NAMESPACE_INLINE_FUNCTION
353 void set_win32_resource_module (HINSTANCE
);
355 extern ACE_Export ACE_TEXT_OSVERSIONINFO win32_versioninfo_
;
357 extern ACE_Export HINSTANCE win32_resource_module_
;
359 #endif /* ACE_WIN32 */
361 #ifdef ACE_STDIO_USE_STDLIB_FOR_VARARGS
365 int fprintf (FILE *fp
, const char *format
, ...)
366 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 2, 3);
369 # if defined (ACE_HAS_WCHAR)
371 int fprintf (FILE *fp
, const wchar_t *format
, ...);
372 # endif /* ACE_HAS_WCHAR */
374 ACE_NAMESPACE_INLINE_FUNCTION
378 ACE_NAMESPACE_INLINE_FUNCTION
382 ACE_NAMESPACE_INLINE_FUNCTION
386 ACE_NAMESPACE_INLINE_FUNCTION
387 int fputs (const char *s
,
390 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FPUTWS)
391 ACE_NAMESPACE_INLINE_FUNCTION
392 int fputs (const wchar_t *s
,
394 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FPUTWS */
396 ACE_NAMESPACE_INLINE_FUNCTION
397 size_t fread (void *ptr
,
402 ACE_NAMESPACE_INLINE_FUNCTION
403 FILE *freopen (const ACE_TCHAR
*filename
,
404 const ACE_TCHAR
*mode
,
407 ACE_NAMESPACE_INLINE_FUNCTION
412 ACE_NAMESPACE_INLINE_FUNCTION
413 int fsetpos (FILE* fp
, fpos_t* pos
);
415 ACE_NAMESPACE_INLINE_FUNCTION
416 long ftell (FILE* fp
);
418 ACE_NAMESPACE_INLINE_FUNCTION
419 size_t fwrite (const void *ptr
,
424 ACE_NAMESPACE_INLINE_FUNCTION
425 void perror (const char *s
);
427 #if defined (ACE_HAS_WCHAR)
428 ACE_NAMESPACE_INLINE_FUNCTION
429 void perror (const wchar_t *s
);
430 #endif /* ACE_HAS_WCHAR */
432 #if defined ACE_FACE_DEV && defined ACE_STDIO_USE_STDLIB_FOR_VARARGS
436 int printf (const char *format
, ...)
437 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 1, 2);
440 #if defined (ACE_HAS_WCHAR)
442 int printf (const wchar_t *format
, ...);
445 ACE_NAMESPACE_INLINE_FUNCTION
446 int puts (const char *s
);
448 #if defined (ACE_HAS_WCHAR)
449 ACE_NAMESPACE_INLINE_FUNCTION
450 int puts (const wchar_t *s
);
451 #endif /* ACE_HAS_WCHAR */
453 ACE_NAMESPACE_INLINE_FUNCTION
454 int rename (const char *old_name
,
455 const char *new_name
,
458 #if defined (ACE_HAS_WCHAR)
459 ACE_NAMESPACE_INLINE_FUNCTION
460 int rename (const wchar_t *old_name
,
461 const wchar_t *new_name
,
463 #endif /* ACE_HAS_WCHAR */
465 ACE_NAMESPACE_INLINE_FUNCTION
466 void rewind (FILE *fp
);
468 #if defined ACE_STDIO_USE_STDLIB_FOR_VARARGS && !defined ACE_LACKS_SNPRINTF
472 int snprintf (char *buf
, size_t maxlen
, const char *format
, ...)
473 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 3, 4);
476 # if defined (ACE_HAS_WCHAR)
478 int snprintf (wchar_t *buf
, size_t maxlen
, const wchar_t *format
, ...);
479 # endif /* ACE_HAS_WCHAR */
482 int sprintf (char *buf
, const char *format
, ...)
483 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 2, 3);
485 # if defined (ACE_HAS_WCHAR)
487 int sprintf (wchar_t *buf
, const wchar_t *format
, ...);
488 # endif /* ACE_HAS_WCHAR */
490 # if !defined (ACE_DISABLE_TEMPNAM)
491 ACE_NAMESPACE_INLINE_FUNCTION
492 char *tempnam (const char *dir
= 0,
493 const char *pfx
= 0);
495 # if defined (ACE_HAS_WCHAR)
496 ACE_NAMESPACE_INLINE_FUNCTION
497 wchar_t *tempnam (const wchar_t *dir
,
498 const wchar_t *pfx
= 0);
499 # endif /* ACE_HAS_WCHAR */
500 # endif /* !ACE_DISABLE_TEMPNAM */
502 ACE_NAMESPACE_INLINE_FUNCTION
503 int vasprintf (char **bufp
, const char *format
, va_list argptr
)
504 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 2, 0);
506 ACE_NAMESPACE_INLINE_FUNCTION
507 int vprintf (const char *format
, va_list argptr
)
508 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 1, 0);
510 ACE_NAMESPACE_INLINE_FUNCTION
511 int vfprintf (FILE *fp
, const char *format
, va_list argptr
)
512 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 2, 0);
514 ACE_NAMESPACE_INLINE_FUNCTION
515 int vsprintf (char *buffer
, const char *format
, va_list argptr
)
516 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 2, 0);
518 ACE_NAMESPACE_INLINE_FUNCTION
519 int vsnprintf (char *buffer
, size_t maxlen
, const char *format
, va_list argptr
)
520 ACE_GCC_FORMAT_ATTRIBUTE (printf
, 3, 0);
522 #if defined (ACE_HAS_WCHAR)
523 ACE_NAMESPACE_INLINE_FUNCTION
524 int vasprintf (wchar_t **bufp
, const wchar_t *format
, va_list argptr
);
526 ACE_NAMESPACE_INLINE_FUNCTION
527 int vprintf (const wchar_t *format
, va_list argptr
);
529 ACE_NAMESPACE_INLINE_FUNCTION
530 int vfprintf (FILE *fp
, const wchar_t *format
, va_list argptr
);
532 ACE_NAMESPACE_INLINE_FUNCTION
533 int vsprintf (wchar_t *buffer
, const wchar_t *format
, va_list argptr
);
535 ACE_NAMESPACE_INLINE_FUNCTION
536 int vsnprintf (wchar_t *buffer
, size_t maxlen
, const wchar_t *format
, va_list argptr
);
537 #endif /* ACE_HAS_WCHAR */
539 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
541 int vsnprintf_emulation (char *buf
, size_t max
, const char *fmt
, va_list ap
);
544 #if !defined (ACE_HAS_VASPRINTF) && !defined (ACE_LACKS_VA_COPY)
546 int vasprintf_emulation (char **bufp
, const char *format
, va_list argptr
);
549 #if !defined (ACE_HAS_VASWPRINTF) && !defined (ACE_LACKS_VA_COPY)
550 #if defined (ACE_HAS_WCHAR)
552 int vaswprintf_emulation (wchar_t **bufp
, const wchar_t *format
, va_list argptr
);
553 #endif /* ACE_HAS_WCHAR */
554 #endif /* !ACE_HAS_VASWPRINTF */
556 } /* namespace ACE_OS */
558 ACE_END_VERSIONED_NAMESPACE_DECL
560 # if defined (ACE_HAS_INLINED_OSCALLS)
561 # if defined (ACE_INLINE)
563 # endif /* ACE_INLINE */
564 # define ACE_INLINE inline
565 # include "ace/OS_NS_stdio.inl"
566 # endif /* ACE_HAS_INLINED_OSCALLS */
568 # include /**/ "ace/post.h"
569 #endif /* ACE_OS_NS_STDIO_H */