OS_NS_stdio.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_NS_stdio.h
00006  *
00007  *  $Id: OS_NS_stdio.h 78422 2007-05-21 06:00:24Z olli $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  *  @author Jesper S. M|ller<stophph@diku.dk>
00011  *  @author and a cast of thousands...
00012  *
00013  *  Originally in OS.h.
00014  */
00015 //=============================================================================
00016 
00017 #ifndef ACE_OS_NS_STDIO_H
00018 # define ACE_OS_NS_STDIO_H
00019 
00020 # include /**/ "ace/pre.h"
00021 
00022 # include "ace/config-all.h"
00023 
00024 # if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 #  pragma once
00026 # endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 #include "ace/os_include/os_stdio.h"
00029 #include "ace/os_include/os_fcntl.h"
00030 #include /**/ "ace/ACE_export.h"
00031 
00032 /* OPENVMS needs unistd for cuserid() */
00033 #if defined (CYGWIN32) || defined (ACE_OPENVMS)
00034 #  include "ace/os_include/os_unistd.h"
00035 #endif /* CYGWIN32 || ACE_OPENVMS */
00036 
00037 #if defined (ACE_EXPORT_MACRO)
00038 #  undef ACE_EXPORT_MACRO
00039 #endif
00040 #define ACE_EXPORT_MACRO ACE_Export
00041 
00042 /*
00043  * We inline and undef some functions that may be implemented
00044  * as macros on some platforms. This way macro definitions will
00045  * be usable later as there is no way to save the macro definition
00046  * using the pre-processor.
00047  *
00048  */
00049 #if !defined (ACE_LACKS_CLEARERR)
00050 inline void ace_clearerr_helper (FILE *stream)
00051 {
00052 #  if defined (clearerr)
00053   clearerr (stream);
00054 #  undef clearerr
00055 #  else
00056   ACE_STD_NAMESPACE::clearerr (stream);
00057 #  endif /* defined (clearerr) */
00058 }
00059 #endif /* !ACE_LACKS_CLEARERR */
00060 
00061 inline int ace_fgetc_helper (FILE *fp)
00062 {
00063 #if defined (fgetc)
00064   return fgetc (fp);
00065 #undef fgetc
00066 #else
00067   return ACE_STD_NAMESPACE::fgetc (fp);
00068 #endif /* defined (fgetc) */
00069 }
00070 
00071 inline int ace_fputc_helper (int ch, FILE *fp)
00072 {
00073 #if defined (fputc)
00074   return fputc (ch, fp);
00075 #undef fputc
00076 #else
00077   return ACE_STD_NAMESPACE::fputc (ch, fp);
00078 #endif /* defined (fputc) */
00079 }
00080 
00081 inline int ace_getc_helper (FILE *fp)
00082 {
00083 #if defined (getc)
00084   return getc (fp);
00085 #undef getc
00086 #else
00087   return ACE_STD_NAMESPACE::getc (fp);
00088 #endif /* defined (getc) */
00089 }
00090 
00091 inline int ace_putc_helper (int ch, FILE *fp)
00092 {
00093 #if defined (putc)
00094   return putc (ch, fp);
00095 #undef putc
00096 #else
00097   return ACE_STD_NAMESPACE::putc (ch, fp);
00098 #endif /* defined (putc) */
00099 }
00100 
00101 inline int ace_ungetc_helper (int ch, FILE *fp)
00102 {
00103 #if defined (ungetc)
00104   return ungetc (ch, fp);
00105 #undef ungetc
00106 #else
00107   return ACE_STD_NAMESPACE::ungetc (ch, fp);
00108 #endif /* defined (ungetc) */
00109 }
00110 
00111 
00112 #if !defined (ACE_LACKS_CUSERID) && !defined(ACE_HAS_ALT_CUSERID) \
00113     && !defined(ACE_WIN32) && !defined (ACE_VXWORKS)
00114 /// Helper for the ACE_OS::cuserid() function
00115 /**
00116  * On some platforms cuserid is a macro.  Defining ACE_OS::cuserid()
00117  * becomes really hard, as there is no way to save the macro
00118  * definition using the pre-processor.
00119  * This inline function achieves the same effect, without namespace
00120  * pollution or performance penalties.
00121  *
00122  * @todo We maybe should move a lot of the code in ACE_OS::cuserid here so
00123  *       it is treated the same as the above ace_difftime and ace_timezone.
00124  *       But since there is a good deal more code in ACE_OS::cuserid, we
00125  *       probably need to move some of it off into some sort of emulation
00126  *       function.
00127  */
00128 inline char *ace_cuserid(char *user)
00129 {
00130   return cuserid(user);
00131 }
00132 #endif /* !ACE_LACKS_CUSERID && !ACE_HAS_ALT_CUSERID && ... */
00133 
00134 # if defined (ACE_LACKS_FILELOCKS)
00135 #   if ! defined (ACE_VXWORKS) && ! defined (ACE_HAS_RTEMS) && !defined (INTEGRITY)
00136 // VxWorks defines struct flock in sys/fcntlcom.h.  But it doesn't
00137 // appear to support flock ().  RTEMS defines struct flock but
00138 // currently does not support locking.
00139 struct flock
00140 {
00141   short l_type;
00142   short l_whence;
00143   ACE_OFF_T l_start;
00144   ACE_OFF_T l_len;          /* len == 0 means until end of file */
00145   long  l_sysid;
00146   pid_t l_pid;
00147   long  l_pad[4];               /* reserve area */
00148 };
00149 #   endif /* ! VXWORKS */
00150 # endif /* ACE_LACKS_FILELOCKS */
00151 
00152 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00153 
00154 namespace ACE_OS {
00155 
00156   /**
00157    * @class ace_flock_t
00158    *
00159    * @brief OS file locking structure.
00160    */
00161   class ACE_Export ace_flock_t
00162   {
00163   public:
00164   /// Dump state of the object.
00165     void dump (void) const;
00166 
00167 # if defined (ACE_WIN32)
00168     ACE_OVERLAPPED overlapped_;
00169 # else
00170     struct flock lock_;
00171 # endif /* ACE_WIN32 */
00172 
00173     /// Name of this filelock.
00174     const ACE_TCHAR *lockname_;
00175 
00176     /// Handle to the underlying file.
00177     ACE_HANDLE handle_;
00178   };
00179 
00180 # if defined (ACE_USES_WCHAR)
00181   // If fp points to the Unicode format file, the file pointer will be moved right next
00182   // to the Unicode header (2 types).  Otherwise, file pointer will be at the beginning.
00183   extern ACE_Export
00184   void checkUnicodeFormat (FILE* fp);
00185 # endif  // ACE_USES_WCHAR
00186 
00187 # if !defined (ACE_LACKS_CLEARERR)
00188   ACE_NAMESPACE_INLINE_FUNCTION
00189   void clearerr (FILE* fp);
00190 # endif /* !ACE_LACKS_CLEARERR */
00191 
00192   //@{ @name Wrappers to obtain the current user id
00193   // Legacy as per SUSV3
00194 # if !defined (ACE_LACKS_CUSERID)
00195 #   if defined(cuserid)
00196 #     undef cuserid
00197 #   endif /* cuserid */
00198 
00199   ACE_NAMESPACE_INLINE_FUNCTION
00200   char *cuserid (char *user,
00201                  size_t maxlen = ACE_MAX_USERID);
00202 
00203 #   if defined (ACE_HAS_WCHAR)
00204   ACE_NAMESPACE_INLINE_FUNCTION
00205   wchar_t *cuserid (wchar_t *user,
00206                     size_t maxlen = ACE_MAX_USERID);
00207 #   endif /* ACE_HAS_WCHAR */
00208 # endif /* ACE_LACKS_CUSERID */
00209   //@}
00210 
00211   ACE_NAMESPACE_INLINE_FUNCTION
00212   int fclose (FILE *fp);
00213 
00214 # if defined (fdopen)
00215 #   undef fdopen
00216 # endif /* fdopen */
00217 
00218   ACE_NAMESPACE_INLINE_FUNCTION
00219   FILE *fdopen (ACE_HANDLE handle, const ACE_TCHAR *mode);
00220 
00221   ACE_NAMESPACE_INLINE_FUNCTION
00222   int fflush (FILE *fp);
00223 
00224   ACE_NAMESPACE_INLINE_FUNCTION
00225   int fgetc (FILE* fp);
00226 
00227   ACE_NAMESPACE_INLINE_FUNCTION
00228   int getc (FILE* fp);
00229 
00230   ACE_NAMESPACE_INLINE_FUNCTION
00231   int fgetpos (FILE* fp, fpos_t* pos);
00232 
00233   ACE_NAMESPACE_INLINE_FUNCTION
00234   char *fgets (char *buf, int size, FILE *fp);
00235 
00236 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FGETWS)
00237   ACE_NAMESPACE_INLINE_FUNCTION
00238   wchar_t *fgets (wchar_t *buf, int size, FILE *fp);
00239 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FGETWS */
00240 
00241   //@{ @name A set of wrappers for file locks.
00242 
00243 # if defined (ACE_WIN32)
00244   ACE_NAMESPACE_INLINE_FUNCTION
00245   void flock_adjust_params (ace_flock_t *lock,
00246                             short whence,
00247                             ACE_OFF_T &start,
00248                             ACE_OFF_T &len);
00249 # endif /* ACE_WIN32 */
00250 
00251   ACE_NAMESPACE_INLINE_FUNCTION
00252   int flock_init (ace_flock_t *lock,
00253                   int flags = 0,
00254                   const ACE_TCHAR *name = 0,
00255                   mode_t perms = 0);
00256 
00257   ACE_NAMESPACE_INLINE_FUNCTION
00258   int flock_destroy (ace_flock_t *lock,
00259                      int unlink_file = 1);
00260 
00261   ACE_NAMESPACE_INLINE_FUNCTION
00262   int flock_rdlock (ace_flock_t *lock,
00263                     short whence = 0,
00264                     ACE_OFF_T start = 0,
00265                     ACE_OFF_T len = 0);
00266 
00267   ACE_NAMESPACE_INLINE_FUNCTION
00268   int flock_tryrdlock (ace_flock_t *lock,
00269                        short whence = 0,
00270                        ACE_OFF_T start = 0,
00271                        ACE_OFF_T len = 0);
00272 
00273   ACE_NAMESPACE_INLINE_FUNCTION
00274   int flock_trywrlock (ace_flock_t *lock,
00275                        short whence = 0,
00276                        ACE_OFF_T start = 0,
00277                        ACE_OFF_T len = 0);
00278 
00279   ACE_NAMESPACE_INLINE_FUNCTION
00280   int flock_unlock (ace_flock_t *lock,
00281                     short whence = 0,
00282                     ACE_OFF_T start = 0,
00283                     ACE_OFF_T len = 0);
00284 
00285   ACE_NAMESPACE_INLINE_FUNCTION
00286   int flock_wrlock (ace_flock_t *lock,
00287                     short whence = 0,
00288                     ACE_OFF_T start = 0,
00289                     ACE_OFF_T len = 0);
00290 
00291   //@}
00292 
00293 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00294   extern ACE_Export
00295 #else
00296   ACE_NAMESPACE_INLINE_FUNCTION
00297 #endif /* ACE_WIN32 */
00298   FILE *fopen (const char *filename, const ACE_TCHAR *mode);
00299 
00300 #if defined (ACE_HAS_WCHAR)
00301 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00302   extern ACE_Export
00303 #else
00304   ACE_NAMESPACE_INLINE_FUNCTION
00305 #endif /* ACE_WIN32 */
00306   FILE *fopen (const wchar_t *filename, const ACE_TCHAR *mode);
00307 #endif /* ACE_HAS_WCHAR */
00308 
00309 #if defined (ACE_WIN32)
00310   /// Default Win32 Security Attributes definition.
00311   ACE_NAMESPACE_INLINE_FUNCTION
00312   LPSECURITY_ATTRIBUTES default_win32_security_attributes (LPSECURITY_ATTRIBUTES);
00313   ACE_NAMESPACE_INLINE_FUNCTION
00314   LPSECURITY_ATTRIBUTES default_win32_security_attributes_r (LPSECURITY_ATTRIBUTES,
00315                                              LPSECURITY_ATTRIBUTES,
00316                                              SECURITY_DESCRIPTOR*);
00317 
00318   // = Win32 OS version determination function.
00319   /// Return the win32 OSVERSIONINFO structure.
00320   ACE_NAMESPACE_INLINE_FUNCTION
00321   const ACE_TEXT_OSVERSIONINFO &get_win32_versioninfo (void);
00322 
00323   // = A pair of functions for modifying ACE's Win32 resource usage.
00324   /// Return the handle of the module containing ACE's resources. By
00325   /// default, for a DLL build of ACE this is a handle to the ACE DLL
00326   /// itself, and for a static build it is a handle to the executable.
00327   ACE_NAMESPACE_INLINE_FUNCTION
00328   HINSTANCE get_win32_resource_module (void);
00329 
00330   /// Allow an application to modify which module contains ACE's
00331   /// resources. This is mainly useful for a static build of ACE where
00332   /// the required resources reside somewhere other than the executable.
00333   ACE_NAMESPACE_INLINE_FUNCTION
00334   void set_win32_resource_module (HINSTANCE);
00335 
00336   extern ACE_Export ACE_TEXT_OSVERSIONINFO win32_versioninfo_;
00337 
00338   extern ACE_Export HINSTANCE win32_resource_module_;
00339 
00340 #endif /* ACE_WIN32 */
00341 
00342   extern ACE_Export
00343   int fprintf (FILE *fp, const char *format, ...);
00344 
00345 # if defined (ACE_HAS_WCHAR)
00346   extern ACE_Export
00347   int fprintf (FILE *fp, const wchar_t *format, ...);
00348 # endif /* ACE_HAS_WCHAR */
00349 
00350   ACE_NAMESPACE_INLINE_FUNCTION
00351   int ungetc (int c,
00352               FILE *fp);
00353 
00354   ACE_NAMESPACE_INLINE_FUNCTION
00355   int fputc (int c,
00356              FILE *fp);
00357 
00358   ACE_NAMESPACE_INLINE_FUNCTION
00359   int putc (int c,
00360             FILE *fp);
00361 
00362   ACE_NAMESPACE_INLINE_FUNCTION
00363   int fputs (const char *s,
00364              FILE *stream);
00365 
00366 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FPUTWS)
00367   ACE_NAMESPACE_INLINE_FUNCTION
00368   int fputs (const wchar_t *s,
00369              FILE *stream);
00370 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FPUTWS */
00371 
00372   ACE_NAMESPACE_INLINE_FUNCTION
00373   size_t fread (void *ptr,
00374                 size_t size,
00375                 size_t nelems,
00376                 FILE *fp);
00377 
00378   ACE_NAMESPACE_INLINE_FUNCTION
00379   FILE *freopen (const ACE_TCHAR *filename,
00380                  const ACE_TCHAR *mode,
00381                  FILE* stream);
00382 
00383   ACE_NAMESPACE_INLINE_FUNCTION
00384   int fseek (FILE *fp,
00385              long offset,
00386              int ptrname);
00387 
00388   ACE_NAMESPACE_INLINE_FUNCTION
00389   int  fsetpos (FILE* fp, fpos_t* pos);
00390 
00391   ACE_NAMESPACE_INLINE_FUNCTION
00392   long ftell (FILE* fp);
00393 
00394   ACE_NAMESPACE_INLINE_FUNCTION
00395   size_t fwrite (const void *ptr,
00396                  size_t size,
00397                  size_t nitems,
00398                  FILE *fp);
00399 
00400   ACE_NAMESPACE_INLINE_FUNCTION
00401   void perror (const char *s);
00402 
00403 #if defined (ACE_HAS_WCHAR)
00404   ACE_NAMESPACE_INLINE_FUNCTION
00405   void perror (const wchar_t *s);
00406 #endif /* ACE_HAS_WCHAR */
00407 
00408   extern ACE_Export
00409   int printf (const char *format, ...);
00410 
00411   ACE_NAMESPACE_INLINE_FUNCTION
00412   int puts (const char *s);
00413 
00414 #if defined (ACE_HAS_WCHAR)
00415   ACE_NAMESPACE_INLINE_FUNCTION
00416   int puts (const wchar_t *s);
00417 #endif /* ACE_HAS_WCHAR */
00418 
00419   ACE_NAMESPACE_INLINE_FUNCTION
00420   int rename (const char *old_name,
00421               const char *new_name,
00422               int flags = -1);
00423 
00424 #if defined (ACE_HAS_WCHAR)
00425   ACE_NAMESPACE_INLINE_FUNCTION
00426   int rename (const wchar_t *old_name,
00427               const wchar_t *new_name,
00428               int flags = -1);
00429 #endif /* ACE_HAS_WCHAR */
00430 
00431   ACE_NAMESPACE_INLINE_FUNCTION
00432   void rewind (FILE *fp);
00433 
00434   extern ACE_Export
00435   int snprintf (char *buf, size_t maxlen, const char *format, ...);
00436 
00437 # if defined (ACE_HAS_WCHAR)
00438   extern ACE_Export
00439   int snprintf (wchar_t *buf, size_t maxlen, const wchar_t *format, ...);
00440 # endif /* ACE_HAS_WCHAR */
00441 
00442   extern ACE_Export
00443   int sprintf (char *buf, const char *format, ...);
00444 
00445 # if defined (ACE_HAS_WCHAR)
00446   extern ACE_Export
00447   int sprintf (wchar_t *buf, const wchar_t *format, ...);
00448 # endif /* ACE_HAS_WCHAR */
00449 
00450   ACE_NAMESPACE_INLINE_FUNCTION
00451   char *tempnam (const char *dir = 0,
00452                  const char *pfx = 0);
00453 
00454 #if defined (ACE_HAS_WCHAR)
00455   ACE_NAMESPACE_INLINE_FUNCTION
00456   wchar_t *tempnam (const wchar_t *dir,
00457                     const wchar_t *pfx = 0);
00458 #endif /* ACE_HAS_WCHAR */
00459 
00460   ACE_NAMESPACE_INLINE_FUNCTION
00461   int vsprintf (char *buffer, const char *format, va_list argptr);
00462 
00463   ACE_NAMESPACE_INLINE_FUNCTION
00464   int vsnprintf (char *buffer, size_t maxlen, const char *format, va_list argptr);
00465 
00466 # if defined (ACE_HAS_WCHAR)
00467   ACE_NAMESPACE_INLINE_FUNCTION
00468   int vsprintf (wchar_t *buffer, const wchar_t *format, va_list argptr);
00469 
00470   ACE_NAMESPACE_INLINE_FUNCTION
00471   int vsnprintf (wchar_t *buffer, size_t maxlen, const wchar_t *format, va_list argptr);
00472 # endif /* ACE_HAS_WCHAR */
00473 
00474 } /* namespace ACE_OS */
00475 
00476 ACE_END_VERSIONED_NAMESPACE_DECL
00477 
00478 # if defined (ACE_HAS_INLINED_OSCALLS)
00479 #   if defined (ACE_INLINE)
00480 #     undef ACE_INLINE
00481 #   endif /* ACE_INLINE */
00482 #   define ACE_INLINE inline
00483 #   include "ace/OS_NS_stdio.inl"
00484 # endif /* ACE_HAS_INLINED_OSCALLS */
00485 
00486 # include /**/ "ace/post.h"
00487 #endif /* ACE_OS_NS_STDIO_H */

Generated on Sun Jan 27 12:05:33 2008 for ACE by doxygen 1.3.6