3 //=============================================================================
7 * $Id: OS_NS_stdio.h 81840 2008-06-05 13:46:45Z sma $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
10 * @author Jesper S. M|ller<stophph@diku.dk>
11 * @author and a cast of thousands...
15 //=============================================================================
17 #ifndef ACE_OS_NS_STDIO_H
18 # define ACE_OS_NS_STDIO_H
20 # include /**/ "ace/pre.h"
22 # include "ace/config-all.h"
24 # if !defined (ACE_LACKS_PRAGMA_ONCE)
26 # endif /* ACE_LACKS_PRAGMA_ONCE */
28 #include "ace/os_include/os_stdio.h"
29 #include "ace/os_include/os_fcntl.h"
30 #include /**/ "ace/ACE_export.h"
32 /* OPENVMS needs unistd for cuserid() */
33 #if defined (CYGWIN32) || defined (ACE_OPENVMS)
34 # include "ace/os_include/os_unistd.h"
35 #endif /* CYGWIN32 || ACE_OPENVMS */
37 #if defined (ACE_EXPORT_MACRO)
38 # undef ACE_EXPORT_MACRO
40 #define ACE_EXPORT_MACRO ACE_Export
43 * We inline and undef some functions that may be implemented
44 * as macros on some platforms. This way macro definitions will
45 * be usable later as there is no way to save the macro definition
46 * using the pre-processor.
49 #if !defined (ACE_LACKS_CLEARERR)
50 inline void ace_clearerr_helper (FILE *stream
)
52 # if defined (clearerr)
56 ACE_STD_NAMESPACE::clearerr (stream
);
57 # endif /* defined (clearerr) */
59 #endif /* !ACE_LACKS_CLEARERR */
61 inline int ace_fgetc_helper (FILE *fp
)
67 return ACE_STD_NAMESPACE::fgetc (fp
);
68 #endif /* defined (fgetc) */
71 inline int ace_fputc_helper (int ch
, FILE *fp
)
74 return fputc (ch
, fp
);
77 return ACE_STD_NAMESPACE::fputc (ch
, fp
);
78 #endif /* defined (fputc) */
81 inline int ace_getc_helper (FILE *fp
)
87 return ACE_STD_NAMESPACE::getc (fp
);
88 #endif /* defined (getc) */
91 inline int ace_putc_helper (int ch
, FILE *fp
)
97 return ACE_STD_NAMESPACE::putc (ch
, fp
);
98 #endif /* defined (putc) */
101 inline int ace_ungetc_helper (int ch
, FILE *fp
)
104 return ungetc (ch
, fp
);
107 return ACE_STD_NAMESPACE::ungetc (ch
, fp
);
108 #endif /* defined (ungetc) */
112 #if !defined (ACE_LACKS_CUSERID) && !defined(ACE_HAS_ALT_CUSERID) \
113 && !defined(ACE_WIN32) && !defined (ACE_VXWORKS)
114 /// Helper for the ACE_OS::cuserid() function
116 * On some platforms cuserid is a macro. Defining ACE_OS::cuserid()
117 * becomes really hard, as there is no way to save the macro
118 * definition using the pre-processor.
119 * This inline function achieves the same effect, without namespace
120 * pollution or performance penalties.
122 * @todo We maybe should move a lot of the code in ACE_OS::cuserid here so
123 * it is treated the same as the above ace_difftime and ace_timezone.
124 * But since there is a good deal more code in ACE_OS::cuserid, we
125 * probably need to move some of it off into some sort of emulation
128 inline char *ace_cuserid(char *user
)
130 return cuserid(user
);
132 #endif /* !ACE_LACKS_CUSERID && !ACE_HAS_ALT_CUSERID && ... */
134 # if defined (ACE_LACKS_FILELOCKS)
135 # if ! defined (ACE_VXWORKS) && ! defined (ACE_HAS_RTEMS) && !defined (INTEGRITY)
136 // VxWorks defines struct flock in sys/fcntlcom.h. But it doesn't
137 // appear to support flock (). RTEMS defines struct flock but
138 // currently does not support locking.
144 ACE_OFF_T l_len
; /* len == 0 means until end of file */
147 long l_pad
[4]; /* reserve area */
149 # endif /* ! VXWORKS */
150 # endif /* ACE_LACKS_FILELOCKS */
152 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
159 * @brief OS file locking structure.
161 class ACE_Export ace_flock_t
164 /// Dump state of the object.
165 void dump (void) const;
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 # if !defined (ACE_LACKS_CLEARERR)
188 ACE_NAMESPACE_INLINE_FUNCTION
189 void clearerr (FILE* fp
);
190 # endif /* !ACE_LACKS_CLEARERR */
192 //@{ @name Wrappers to obtain the current user id
193 // Legacy as per SUSV3
194 # if !defined (ACE_LACKS_CUSERID)
195 # if defined(cuserid)
197 # endif /* cuserid */
199 ACE_NAMESPACE_INLINE_FUNCTION
200 char *cuserid (char *user
,
201 size_t maxlen
= ACE_MAX_USERID
);
203 # if defined (ACE_HAS_WCHAR)
204 ACE_NAMESPACE_INLINE_FUNCTION
205 wchar_t *cuserid (wchar_t *user
,
206 size_t maxlen
= ACE_MAX_USERID
);
207 # endif /* ACE_HAS_WCHAR */
208 # endif /* ACE_LACKS_CUSERID */
212 int asprintf (char **bufp
, const char* format
, ...);
214 # if defined (ACE_HAS_WCHAR)
216 int asprintf (wchar_t **bufp
, const wchar_t* format
, ...);
217 #endif /* ACE_HAS_WCHAR */
219 ACE_NAMESPACE_INLINE_FUNCTION
220 int fclose (FILE *fp
);
222 # if defined (fdopen)
226 ACE_NAMESPACE_INLINE_FUNCTION
227 FILE *fdopen (ACE_HANDLE handle
, const ACE_TCHAR
*mode
);
229 ACE_NAMESPACE_INLINE_FUNCTION
230 int fflush (FILE *fp
);
232 ACE_NAMESPACE_INLINE_FUNCTION
233 int fgetc (FILE* fp
);
235 ACE_NAMESPACE_INLINE_FUNCTION
238 ACE_NAMESPACE_INLINE_FUNCTION
239 int fgetpos (FILE* fp
, fpos_t* pos
);
241 ACE_NAMESPACE_INLINE_FUNCTION
242 char *fgets (char *buf
, int size
, FILE *fp
);
244 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FGETWS)
245 ACE_NAMESPACE_INLINE_FUNCTION
246 wchar_t *fgets (wchar_t *buf
, int size
, FILE *fp
);
247 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FGETWS */
249 //@{ @name A set of wrappers for file locks.
251 # if defined (ACE_WIN32)
252 ACE_NAMESPACE_INLINE_FUNCTION
253 void flock_adjust_params (ace_flock_t
*lock
,
257 # endif /* ACE_WIN32 */
259 ACE_NAMESPACE_INLINE_FUNCTION
260 int flock_init (ace_flock_t
*lock
,
262 const ACE_TCHAR
*name
= 0,
265 ACE_NAMESPACE_INLINE_FUNCTION
266 int flock_destroy (ace_flock_t
*lock
,
267 int unlink_file
= 1);
269 ACE_NAMESPACE_INLINE_FUNCTION
270 int flock_rdlock (ace_flock_t
*lock
,
275 ACE_NAMESPACE_INLINE_FUNCTION
276 int flock_tryrdlock (ace_flock_t
*lock
,
281 ACE_NAMESPACE_INLINE_FUNCTION
282 int flock_trywrlock (ace_flock_t
*lock
,
287 ACE_NAMESPACE_INLINE_FUNCTION
288 int flock_unlock (ace_flock_t
*lock
,
293 ACE_NAMESPACE_INLINE_FUNCTION
294 int flock_wrlock (ace_flock_t
*lock
,
301 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
304 ACE_NAMESPACE_INLINE_FUNCTION
305 #endif /* ACE_WIN32 */
306 FILE *fopen (const char *filename
, const char *mode
);
308 #if defined (ACE_HAS_WCHAR)
309 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
312 ACE_NAMESPACE_INLINE_FUNCTION
313 #endif /* ACE_WIN32 */
314 FILE *fopen (const char *filename
, const wchar_t *mode
);
315 # if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
318 ACE_NAMESPACE_INLINE_FUNCTION
319 # endif /* ACE_WIN32 */
320 FILE *fopen (const wchar_t *filename
, const wchar_t *mode
);
321 # if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
324 ACE_NAMESPACE_INLINE_FUNCTION
325 # endif /* ACE_WIN32 */
326 FILE *fopen (const wchar_t *filename
, const char *mode
);
327 #endif /* ACE_HAS_WCHAR */
329 #if defined (ACE_WIN32)
330 /// Default Win32 Security Attributes definition.
331 ACE_NAMESPACE_INLINE_FUNCTION
332 LPSECURITY_ATTRIBUTES
default_win32_security_attributes (LPSECURITY_ATTRIBUTES
);
333 ACE_NAMESPACE_INLINE_FUNCTION
334 LPSECURITY_ATTRIBUTES
default_win32_security_attributes_r (LPSECURITY_ATTRIBUTES
,
335 LPSECURITY_ATTRIBUTES
,
336 SECURITY_DESCRIPTOR
*);
338 // = Win32 OS version determination function.
339 /// Return the win32 OSVERSIONINFO structure.
340 ACE_NAMESPACE_INLINE_FUNCTION
341 const ACE_TEXT_OSVERSIONINFO
&get_win32_versioninfo (void);
343 // = A pair of functions for modifying ACE's Win32 resource usage.
344 /// Return the handle of the module containing ACE's resources. By
345 /// default, for a DLL build of ACE this is a handle to the ACE DLL
346 /// itself, and for a static build it is a handle to the executable.
347 ACE_NAMESPACE_INLINE_FUNCTION
348 HINSTANCE
get_win32_resource_module (void);
350 /// Allow an application to modify which module contains ACE's
351 /// resources. This is mainly useful for a static build of ACE where
352 /// the required resources reside somewhere other than the executable.
353 ACE_NAMESPACE_INLINE_FUNCTION
354 void set_win32_resource_module (HINSTANCE
);
356 extern ACE_Export ACE_TEXT_OSVERSIONINFO win32_versioninfo_
;
358 extern ACE_Export HINSTANCE win32_resource_module_
;
360 #endif /* ACE_WIN32 */
363 int fprintf (FILE *fp
, const char *format
, ...);
365 # if defined (ACE_HAS_WCHAR)
367 int fprintf (FILE *fp
, const wchar_t *format
, ...);
368 # endif /* ACE_HAS_WCHAR */
370 ACE_NAMESPACE_INLINE_FUNCTION
374 ACE_NAMESPACE_INLINE_FUNCTION
378 ACE_NAMESPACE_INLINE_FUNCTION
382 ACE_NAMESPACE_INLINE_FUNCTION
383 int fputs (const char *s
,
386 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FPUTWS)
387 ACE_NAMESPACE_INLINE_FUNCTION
388 int fputs (const wchar_t *s
,
390 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FPUTWS */
392 ACE_NAMESPACE_INLINE_FUNCTION
393 size_t fread (void *ptr
,
398 ACE_NAMESPACE_INLINE_FUNCTION
399 FILE *freopen (const ACE_TCHAR
*filename
,
400 const ACE_TCHAR
*mode
,
403 ACE_NAMESPACE_INLINE_FUNCTION
408 ACE_NAMESPACE_INLINE_FUNCTION
409 int fsetpos (FILE* fp
, fpos_t* pos
);
411 ACE_NAMESPACE_INLINE_FUNCTION
412 long ftell (FILE* fp
);
414 ACE_NAMESPACE_INLINE_FUNCTION
415 size_t fwrite (const void *ptr
,
420 ACE_NAMESPACE_INLINE_FUNCTION
421 void perror (const char *s
);
423 #if defined (ACE_HAS_WCHAR)
424 ACE_NAMESPACE_INLINE_FUNCTION
425 void perror (const wchar_t *s
);
426 #endif /* ACE_HAS_WCHAR */
429 int printf (const char *format
, ...);
431 #if defined (ACE_HAS_WCHAR)
433 int printf (const wchar_t *format
, ...);
436 ACE_NAMESPACE_INLINE_FUNCTION
437 int puts (const char *s
);
439 #if defined (ACE_HAS_WCHAR)
440 ACE_NAMESPACE_INLINE_FUNCTION
441 int puts (const wchar_t *s
);
442 #endif /* ACE_HAS_WCHAR */
444 ACE_NAMESPACE_INLINE_FUNCTION
445 int rename (const char *old_name
,
446 const char *new_name
,
449 #if defined (ACE_HAS_WCHAR)
450 ACE_NAMESPACE_INLINE_FUNCTION
451 int rename (const wchar_t *old_name
,
452 const wchar_t *new_name
,
454 #endif /* ACE_HAS_WCHAR */
456 ACE_NAMESPACE_INLINE_FUNCTION
457 void rewind (FILE *fp
);
460 int snprintf (char *buf
, size_t maxlen
, const char *format
, ...);
462 # if defined (ACE_HAS_WCHAR)
464 int snprintf (wchar_t *buf
, size_t maxlen
, const wchar_t *format
, ...);
465 # endif /* ACE_HAS_WCHAR */
468 int sprintf (char *buf
, const char *format
, ...);
470 # if defined (ACE_HAS_WCHAR)
472 int sprintf (wchar_t *buf
, const wchar_t *format
, ...);
473 # endif /* ACE_HAS_WCHAR */
475 ACE_NAMESPACE_INLINE_FUNCTION
476 char *tempnam (const char *dir
= 0,
477 const char *pfx
= 0);
479 #if defined (ACE_HAS_WCHAR)
480 ACE_NAMESPACE_INLINE_FUNCTION
481 wchar_t *tempnam (const wchar_t *dir
,
482 const wchar_t *pfx
= 0);
483 #endif /* ACE_HAS_WCHAR */
485 ACE_NAMESPACE_INLINE_FUNCTION
486 int vasprintf (char **bufp
, const char *format
, va_list argptr
);
488 ACE_NAMESPACE_INLINE_FUNCTION
489 int vprintf (const char *format
, va_list argptr
);
491 ACE_NAMESPACE_INLINE_FUNCTION
492 int vfprintf (FILE *fp
, const char *format
, va_list argptr
);
494 ACE_NAMESPACE_INLINE_FUNCTION
495 int vsprintf (char *buffer
, const char *format
, va_list argptr
);
497 ACE_NAMESPACE_INLINE_FUNCTION
498 int vsnprintf (char *buffer
, size_t maxlen
, const char *format
, va_list argptr
);
500 # if defined (ACE_HAS_WCHAR)
501 ACE_NAMESPACE_INLINE_FUNCTION
502 int vasprintf (wchar_t **bufp
, const wchar_t *format
, va_list argptr
);
504 ACE_NAMESPACE_INLINE_FUNCTION
505 int vprintf (const wchar_t *format
, va_list argptr
);
507 ACE_NAMESPACE_INLINE_FUNCTION
508 int vfprintf (FILE *fp
, const wchar_t *format
, va_list argptr
);
510 ACE_NAMESPACE_INLINE_FUNCTION
511 int vsprintf (wchar_t *buffer
, const wchar_t *format
, va_list argptr
);
513 ACE_NAMESPACE_INLINE_FUNCTION
514 int vsnprintf (wchar_t *buffer
, size_t maxlen
, const wchar_t *format
, va_list argptr
);
515 # endif /* ACE_HAS_WCHAR */
517 #if !defined (ACE_HAS_VASPRINTF)
519 int vasprintf_emulation (char **bufp
, const char *format
, va_list argptr
);
520 #endif /* !ACE_HAS_VASPRINTF */
522 #if defined (ACE_HAS_WCHAR)
523 #if !defined (ACE_HAS_VASWPRINTF)
525 int vaswprintf_emulation (wchar_t **bufp
, const wchar_t *format
, va_list argptr
);
526 #endif /* !ACE_HAS_VASWPRINTF */
527 #endif /* ACE_HAS_WCHAR */
529 } /* namespace ACE_OS */
531 ACE_END_VERSIONED_NAMESPACE_DECL
533 # if defined (ACE_HAS_INLINED_OSCALLS)
534 # if defined (ACE_INLINE)
536 # endif /* ACE_INLINE */
537 # define ACE_INLINE inline
538 # include "ace/OS_NS_stdio.inl"
539 # endif /* ACE_HAS_INLINED_OSCALLS */
541 # include /**/ "ace/post.h"
542 #endif /* ACE_OS_NS_STDIO_H */