Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / OS_NS_stdio.h
blob3d592c526f736e19cc057a2d9cacc2c89713f3f9
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file OS_NS_stdio.h
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)
21 # 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"
32 #endif /* CYGWIN32 */
34 #if defined (ACE_WIN32)
35 # include "io.h"
36 #endif
38 #if defined (ACE_EXPORT_MACRO)
39 # undef ACE_EXPORT_MACRO
40 #endif
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)
51 #if defined (fgetc)
52 return fgetc (fp);
53 #undef fgetc
54 #else
55 return ::fgetc (fp);
56 #endif /* defined (fgetc) */
59 #if !defined (ACE_LACKS_FPUTC)
60 inline int ace_fputc_helper (int ch, FILE *fp)
62 #if defined (fputc)
63 return fputc (ch, fp);
64 #undef fputc
65 #else
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)
74 #if defined (getc)
75 return getc (fp);
76 #undef getc
77 #else
78 return ::getc (fp);
79 #endif /* defined (getc) */
81 #elif defined getc
82 # undef getc
83 #endif /* !ACE_LACKS_GETC */
85 inline int ace_putc_helper (int ch, FILE *fp)
87 #if defined (putc)
88 return putc (ch, fp);
89 #undef putc
90 #elif !defined (ACE_LACKS_PUTC)
91 return ::putc (ch, fp);
92 #else
93 ACE_UNUSED_ARG (ch);
94 ACE_UNUSED_ARG (fp);
95 return -1;
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);
104 # undef fileno
105 # elif defined (ACE_LACKS_FILENO)
106 ACE_UNUSED_ARG (fp);
107 ACE_NOTSUP_RETURN (ACE_INVALID_HANDLE);
108 # else
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
128 * function.
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 ().
140 struct flock
142 short l_type;
143 short l_whence;
144 ACE_OFF_T l_start;
145 ACE_OFF_T l_len; /* len == 0 means until end of file */
146 long l_sysid;
147 pid_t l_pid;
148 long l_pad[4]; /* reserve area */
150 # endif /* ! VXWORKS */
151 # endif /* ACE_LACKS_FILELOCKS */
153 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
155 namespace ACE_OS {
157 * @class ace_flock_t
159 * @brief OS file locking structure.
161 class ACE_Export ace_flock_t
163 public:
164 /// Dump state of the object.
165 void dump () const;
167 # if defined (ACE_WIN32)
168 ACE_OVERLAPPED overlapped_;
169 # else
170 struct flock lock_;
171 # endif /* ACE_WIN32 */
173 /// Name of this filelock.
174 const ACE_TCHAR *lockname_;
176 /// Handle to the underlying file.
177 ACE_HANDLE handle_;
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.
183 extern ACE_Export
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)
194 # undef 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 */
207 //@}
209 extern ACE_Export
210 int asprintf (char **bufp, const char* format, ...)
211 ACE_GCC_FORMAT_ATTRIBUTE (printf, 2, 3);
213 # if defined (ACE_HAS_WCHAR)
214 extern ACE_Export
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
231 int getc (FILE* fp);
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,
249 short whence,
250 ACE_OFF_T &start,
251 ACE_OFF_T &len);
252 # endif /* ACE_WIN32 */
254 ACE_NAMESPACE_INLINE_FUNCTION
255 int flock_init (ace_flock_t *lock,
256 int flags = 0,
257 const ACE_TCHAR *name = 0,
258 mode_t perms = 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,
266 short whence = 0,
267 ACE_OFF_T start = 0,
268 ACE_OFF_T len = 0);
270 ACE_NAMESPACE_INLINE_FUNCTION
271 int flock_tryrdlock (ace_flock_t *lock,
272 short whence = 0,
273 ACE_OFF_T start = 0,
274 ACE_OFF_T len = 0);
276 ACE_NAMESPACE_INLINE_FUNCTION
277 int flock_trywrlock (ace_flock_t *lock,
278 short whence = 0,
279 ACE_OFF_T start = 0,
280 ACE_OFF_T len = 0);
282 ACE_NAMESPACE_INLINE_FUNCTION
283 int flock_unlock (ace_flock_t *lock,
284 short whence = 0,
285 ACE_OFF_T start = 0,
286 ACE_OFF_T len = 0);
288 ACE_NAMESPACE_INLINE_FUNCTION
289 int flock_wrlock (ace_flock_t *lock,
290 short whence = 0,
291 ACE_OFF_T start = 0,
292 ACE_OFF_T len = 0);
294 //@}
297 ACE_NAMESPACE_INLINE_FUNCTION
298 ACE_HANDLE fileno (FILE *stream);
300 #if defined (ACE_WIN32)
301 extern ACE_Export
302 #else
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)
309 extern ACE_Export
310 #else
311 ACE_NAMESPACE_INLINE_FUNCTION
312 #endif /* ACE_WIN32 */
313 FILE *fopen (const char *filename, const wchar_t *mode);
314 # if defined (ACE_WIN32)
315 extern ACE_Export
316 # else
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)
321 extern ACE_Export
322 # else
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
362 using ::fprintf;
363 #else
364 extern ACE_Export
365 int fprintf (FILE *fp, const char *format, ...)
366 ACE_GCC_FORMAT_ATTRIBUTE (printf, 2, 3);
367 #endif
369 # if defined (ACE_HAS_WCHAR)
370 extern ACE_Export
371 int fprintf (FILE *fp, const wchar_t *format, ...);
372 # endif /* ACE_HAS_WCHAR */
374 ACE_NAMESPACE_INLINE_FUNCTION
375 int ungetc (int c,
376 FILE *fp);
378 ACE_NAMESPACE_INLINE_FUNCTION
379 int fputc (int c,
380 FILE *fp);
382 ACE_NAMESPACE_INLINE_FUNCTION
383 int putc (int c,
384 FILE *fp);
386 ACE_NAMESPACE_INLINE_FUNCTION
387 int fputs (const char *s,
388 FILE *stream);
390 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FPUTWS)
391 ACE_NAMESPACE_INLINE_FUNCTION
392 int fputs (const wchar_t *s,
393 FILE *stream);
394 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FPUTWS */
396 ACE_NAMESPACE_INLINE_FUNCTION
397 size_t fread (void *ptr,
398 size_t size,
399 size_t nelems,
400 FILE *fp);
402 ACE_NAMESPACE_INLINE_FUNCTION
403 FILE *freopen (const ACE_TCHAR *filename,
404 const ACE_TCHAR *mode,
405 FILE* stream);
407 ACE_NAMESPACE_INLINE_FUNCTION
408 int fseek (FILE *fp,
409 long offset,
410 int ptrname);
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,
420 size_t size,
421 size_t nitems,
422 FILE *fp);
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
433 using ::printf;
434 #else
435 extern ACE_Export
436 int printf (const char *format, ...)
437 ACE_GCC_FORMAT_ATTRIBUTE (printf, 1, 2);
438 #endif
440 #if defined (ACE_HAS_WCHAR)
441 extern ACE_Export
442 int printf (const wchar_t *format, ...);
443 #endif
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,
456 int flags = -1);
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,
462 int flags = -1);
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
469 using ::snprintf;
470 #else
471 extern ACE_Export
472 int snprintf (char *buf, size_t maxlen, const char *format, ...)
473 ACE_GCC_FORMAT_ATTRIBUTE (printf, 3, 4);
474 #endif
476 # if defined (ACE_HAS_WCHAR)
477 extern ACE_Export
478 int snprintf (wchar_t *buf, size_t maxlen, const wchar_t *format, ...);
479 # endif /* ACE_HAS_WCHAR */
481 extern ACE_Export
482 int sprintf (char *buf, const char *format, ...)
483 ACE_GCC_FORMAT_ATTRIBUTE (printf, 2, 3);
485 # if defined (ACE_HAS_WCHAR)
486 extern ACE_Export
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)
540 extern ACE_Export
541 int vsnprintf_emulation (char *buf, size_t max, const char *fmt, va_list ap);
542 #endif
544 #if !defined (ACE_HAS_VASPRINTF) && !defined (ACE_LACKS_VA_COPY)
545 extern ACE_Export
546 int vasprintf_emulation (char **bufp, const char *format, va_list argptr);
547 #endif
549 #if !defined (ACE_HAS_VASWPRINTF) && !defined (ACE_LACKS_VA_COPY)
550 #if defined (ACE_HAS_WCHAR)
551 extern ACE_Export
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)
562 # undef 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 */