OS_NS_stdio.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_NS_stdio.h
00006  *
00007  *  OS_NS_stdio.h,v 1.22 2006/06/20 12:40:38 jwillemsen Exp
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  * On some platforms clearerr is a macro. Defining ACE_OS::clearerr()
00044  * becomes really hard, as there is no way to save the macro
00045  * definition using the pre-processor.
00046  */
00047 # if !defined (ACE_LACKS_CLEARERR)
00048 #   if defined (clearerr)
00049 #     define __ace_clearerr_hack
00050 inline void __ace_clearerr(FILE *stream)
00051 {
00052   clearerr(stream);
00053 }
00054 #     undef clearerr
00055 #   endif /* defined (clearerr) */
00056 # endif /* !ACE_LACKS_CLEARERR */
00057 
00058 #if !defined (ACE_LACKS_CUSERID) && !defined(ACE_HAS_ALT_CUSERID) \
00059     && !defined(ACE_WIN32) && !defined (ACE_VXWORKS)
00060 /// Helper for the ACE_OS::cuserid() function
00061 /**
00062  * On some platforms cuserid is a macro.  Defining ACE_OS::cuserid()
00063  * becomes really hard, as there is no way to save the macro
00064  * definition using the pre-processor.
00065  * This inline function achieves the same effect, without namespace
00066  * pollution or performance penalties.
00067  *
00068  * @todo We maybe should move a lot of the code in ACE_OS::cuserid here so
00069  *       it is treated the same as the above ace_difftime and ace_timezone.
00070  *       But since there is a good deal more code in ACE_OS::cuserid, we
00071  *       probably need to move some of it off into some sort of emulation
00072  *       function.
00073  */
00074 inline char *ace_cuserid(char *user)
00075 {
00076   return cuserid(user);
00077 }
00078 #endif /* !ACE_LACKS_CUSERID && !ACE_HAS_ALT_CUSERID && ... */
00079 
00080 # if defined (ACE_LACKS_FILELOCKS)
00081 #   if ! defined (ACE_VXWORKS) && ! defined (__rtems__) && !defined (INTEGRITY)
00082 // VxWorks defines struct flock in sys/fcntlcom.h.  But it doesn't
00083 // appear to support flock ().  RTEMS defines struct flock but
00084 // currently does not support locking.
00085 struct flock
00086 {
00087   short l_type;
00088   short l_whence;
00089   off_t l_start;
00090   off_t l_len;          /* len == 0 means until end of file */
00091   long  l_sysid;
00092   pid_t l_pid;
00093   long  l_pad[4];               /* reserve area */
00094 };
00095 #   endif /* ! VXWORKS */
00096 # endif /* ACE_LACKS_FILELOCKS */
00097 
00098 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00099 
00100 namespace ACE_OS {
00101 
00102   /**
00103    * @class ace_flock_t
00104    *
00105    * @brief OS file locking structure.
00106    */
00107   class ACE_Export ace_flock_t
00108   {
00109   public:
00110   /// Dump state of the object.
00111     void dump (void) const;
00112 
00113 # if defined (ACE_WIN32)
00114     ACE_OVERLAPPED overlapped_;
00115 # else
00116     struct flock lock_;
00117 # endif /* ACE_WIN32 */
00118 
00119     /// Name of this filelock.
00120     const ACE_TCHAR *lockname_;
00121 
00122     /// Handle to the underlying file.
00123     ACE_HANDLE handle_;
00124   };
00125 
00126 # if defined (ACE_USES_WCHAR)
00127   // If fp points to the Unicode format file, the file pointer will be moved right next
00128   // to the Unicode header (2 types).  Otherwise, file pointer will be at the beginning.
00129   extern ACE_Export
00130   void checkUnicodeFormat (FILE* fp);
00131 # endif  // ACE_USES_WCHAR
00132 
00133 # if !defined (ACE_LACKS_CLEARERR)
00134   ACE_NAMESPACE_INLINE_FUNCTION
00135   void clearerr (FILE* fp);
00136 # endif /* !ACE_LACKS_CLEARERR */
00137 
00138   //@{ @name Wrappers to obtain the current user id
00139   // Legacy as per SUSV3
00140 # if !defined (ACE_LACKS_CUSERID)
00141 #   if defined(cuserid)
00142 #     undef cuserid
00143 #   endif /* cuserid */
00144 
00145   ACE_NAMESPACE_INLINE_FUNCTION
00146   char *cuserid (char *user,
00147                  size_t maxlen = ACE_MAX_USERID);
00148 
00149 #   if defined (ACE_HAS_WCHAR)
00150   ACE_NAMESPACE_INLINE_FUNCTION
00151   wchar_t *cuserid (wchar_t *user,
00152                     size_t maxlen = ACE_MAX_USERID);
00153 #   endif /* ACE_HAS_WCHAR */
00154 # endif /* ACE_LACKS_CUSERID */
00155   //@}
00156 
00157   ACE_NAMESPACE_INLINE_FUNCTION
00158   int fclose (FILE *fp);
00159 
00160 # if defined (fdopen)
00161 #   undef fdopen
00162 # endif /* fdopen */
00163 
00164   ACE_NAMESPACE_INLINE_FUNCTION
00165   FILE *fdopen (ACE_HANDLE handle, const ACE_TCHAR *mode);
00166 
00167   ACE_NAMESPACE_INLINE_FUNCTION
00168   int fflush (FILE *fp);
00169 
00170   ACE_NAMESPACE_INLINE_FUNCTION
00171   int fgetc (FILE* fp);
00172 
00173   ACE_NAMESPACE_INLINE_FUNCTION
00174   int fgetpos (FILE* fp, fpos_t* pos);
00175 
00176   ACE_NAMESPACE_INLINE_FUNCTION
00177   char *fgets (char *buf, int size, FILE *fp);
00178 
00179 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FGETWS)
00180   ACE_NAMESPACE_INLINE_FUNCTION
00181   wchar_t *fgets (wchar_t *buf, int size, FILE *fp);
00182 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FGETWS */
00183 
00184   //@{ @name A set of wrappers for file locks.
00185 
00186 # if defined (ACE_WIN32)
00187   ACE_NAMESPACE_INLINE_FUNCTION
00188   void flock_adjust_params (ace_flock_t *lock,
00189                             short whence,
00190                             off_t &start,
00191                             off_t &len);
00192 # endif /* ACE_WIN32 */
00193 
00194   ACE_NAMESPACE_INLINE_FUNCTION
00195   int flock_init (ace_flock_t *lock,
00196                   int flags = 0,
00197                   const ACE_TCHAR *name = 0,
00198                   mode_t perms = 0);
00199 
00200   ACE_NAMESPACE_INLINE_FUNCTION
00201   int flock_destroy (ace_flock_t *lock,
00202                      int unlink_file = 1);
00203 
00204   ACE_NAMESPACE_INLINE_FUNCTION
00205   int flock_rdlock (ace_flock_t *lock,
00206                     short whence = 0,
00207                     off_t start = 0,
00208                     off_t len = 0);
00209 
00210   ACE_NAMESPACE_INLINE_FUNCTION
00211   int flock_tryrdlock (ace_flock_t *lock,
00212                        short whence = 0,
00213                        off_t start = 0,
00214                        off_t len = 0);
00215 
00216   ACE_NAMESPACE_INLINE_FUNCTION
00217   int flock_trywrlock (ace_flock_t *lock,
00218                        short whence = 0,
00219                        off_t start = 0,
00220                        off_t len = 0);
00221 
00222   ACE_NAMESPACE_INLINE_FUNCTION
00223   int flock_unlock (ace_flock_t *lock,
00224                     short whence = 0,
00225                     off_t start = 0,
00226                     off_t len = 0);
00227 
00228   ACE_NAMESPACE_INLINE_FUNCTION
00229   int flock_wrlock (ace_flock_t *lock,
00230                     short whence = 0,
00231                     off_t start = 0,
00232                     off_t len = 0);
00233 
00234   //@}
00235 
00236 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00237   extern ACE_Export
00238 #else
00239   ACE_NAMESPACE_INLINE_FUNCTION
00240 #endif /* ACE_WIN32 */
00241   FILE *fopen (const char *filename, const ACE_TCHAR *mode);
00242 
00243 #if defined (ACE_HAS_WCHAR)
00244 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00245   extern ACE_Export
00246 #else
00247   ACE_NAMESPACE_INLINE_FUNCTION
00248 #endif /* ACE_WIN32 */
00249   FILE *fopen (const wchar_t *filename, const ACE_TCHAR *mode);
00250 #endif /* ACE_HAS_WCHAR */
00251 
00252 #if defined (ACE_WIN32)
00253   /// Default Win32 Security Attributes definition.
00254   ACE_NAMESPACE_INLINE_FUNCTION
00255   LPSECURITY_ATTRIBUTES default_win32_security_attributes (LPSECURITY_ATTRIBUTES);
00256   ACE_NAMESPACE_INLINE_FUNCTION
00257   LPSECURITY_ATTRIBUTES default_win32_security_attributes_r (LPSECURITY_ATTRIBUTES,
00258                                              LPSECURITY_ATTRIBUTES,
00259                                              SECURITY_DESCRIPTOR*);
00260 
00261   // = Win32 OS version determination function.
00262   /// Return the win32 OSVERSIONINFO structure.
00263   ACE_NAMESPACE_INLINE_FUNCTION
00264   const OSVERSIONINFO &get_win32_versioninfo (void);
00265 
00266   // = A pair of functions for modifying ACE's Win32 resource usage.
00267   /// Return the handle of the module containing ACE's resources. By
00268   /// default, for a DLL build of ACE this is a handle to the ACE DLL
00269   /// itself, and for a static build it is a handle to the executable.
00270   ACE_NAMESPACE_INLINE_FUNCTION
00271   HINSTANCE get_win32_resource_module (void);
00272 
00273   /// Allow an application to modify which module contains ACE's
00274   /// resources. This is mainly useful for a static build of ACE where
00275   /// the required resources reside somewhere other than the executable.
00276   ACE_NAMESPACE_INLINE_FUNCTION
00277   void set_win32_resource_module (HINSTANCE);
00278 
00279   /// Translate fopen's mode char to open's mode.  This helper function
00280   /// is here to avoid maintaining several pieces of identical code.
00281   ACE_NAMESPACE_INLINE_FUNCTION
00282   void fopen_mode_to_open_mode_converter (ACE_TCHAR x, int &hmode);
00283 
00284   extern ACE_Export OSVERSIONINFO win32_versioninfo_;
00285 
00286   extern ACE_Export HINSTANCE win32_resource_module_;
00287 
00288 #endif /* ACE_WIN32 */
00289 
00290   extern ACE_Export
00291   int fprintf (FILE *fp, const char *format, ...);
00292 
00293 # if defined (ACE_HAS_WCHAR)
00294   extern ACE_Export
00295   int fprintf (FILE *fp, const wchar_t *format, ...);
00296 # endif /* ACE_HAS_WCHAR */
00297 
00298   ACE_NAMESPACE_INLINE_FUNCTION
00299   int fputs (const char *s,
00300              FILE *stream);
00301 
00302 # if defined (ACE_HAS_WCHAR) && !defined(ACE_LACKS_FPUTWS)
00303   ACE_NAMESPACE_INLINE_FUNCTION
00304   int fputs (const wchar_t *s,
00305              FILE *stream);
00306 # endif /* ACE_HAS_WCHAR && !ACE_LACKS_FPUTWS */
00307 
00308   ACE_NAMESPACE_INLINE_FUNCTION
00309   size_t fread (void *ptr,
00310                 size_t size,
00311                 size_t nelems,
00312                 FILE *fp);
00313 
00314   ACE_NAMESPACE_INLINE_FUNCTION
00315   FILE *freopen (const ACE_TCHAR *filename,
00316                  const ACE_TCHAR *mode,
00317                  FILE* stream);
00318 
00319   ACE_NAMESPACE_INLINE_FUNCTION
00320   int fseek (FILE *fp,
00321              long offset,
00322              int ptrname);
00323 
00324   ACE_NAMESPACE_INLINE_FUNCTION
00325   int  fsetpos (FILE* fp, fpos_t* pos);
00326 
00327   ACE_NAMESPACE_INLINE_FUNCTION
00328   long ftell (FILE* fp);
00329 
00330   ACE_NAMESPACE_INLINE_FUNCTION
00331   size_t fwrite (const void *ptr,
00332                  size_t size,
00333                  size_t nitems,
00334                  FILE *fp);
00335 
00336   ACE_NAMESPACE_INLINE_FUNCTION
00337   void perror (const char *s);
00338 
00339 #if defined (ACE_HAS_WCHAR)
00340   ACE_NAMESPACE_INLINE_FUNCTION
00341   void perror (const wchar_t *s);
00342 #endif /* ACE_HAS_WCHAR */
00343 
00344   extern ACE_Export
00345   int printf (const char *format, ...);
00346 
00347   ACE_NAMESPACE_INLINE_FUNCTION
00348   int puts (const char *s);
00349 
00350 #if defined (ACE_HAS_WCHAR)
00351   ACE_NAMESPACE_INLINE_FUNCTION
00352   int puts (const wchar_t *s);
00353 #endif /* ACE_HAS_WCHAR */
00354 
00355   ACE_NAMESPACE_INLINE_FUNCTION
00356   int rename (const char *old_name,
00357               const char *new_name,
00358               int flags = -1);
00359 
00360 #if defined (ACE_HAS_WCHAR)
00361   ACE_NAMESPACE_INLINE_FUNCTION
00362   int rename (const wchar_t *old_name,
00363               const wchar_t *new_name,
00364               int flags = -1);
00365 #endif /* ACE_HAS_WCHAR */
00366 
00367   ACE_NAMESPACE_INLINE_FUNCTION
00368   void rewind (FILE *fp);
00369 
00370   extern ACE_Export
00371   int snprintf (char *buf, size_t maxlen, const char *format, ...);
00372 
00373 # if defined (ACE_HAS_WCHAR)
00374   extern ACE_Export
00375   int snprintf (wchar_t *buf, size_t maxlen, const wchar_t *format,...);
00376 # endif /* ACE_HAS_WCHAR */
00377 
00378   extern ACE_Export
00379   int sprintf (char *buf, const char *format, ...);
00380 
00381 # if defined (ACE_HAS_WCHAR)
00382   extern ACE_Export
00383   int sprintf (wchar_t *buf, const wchar_t *format, ...);
00384 # endif /* ACE_HAS_WCHAR */
00385 
00386   ACE_NAMESPACE_INLINE_FUNCTION
00387   char *tempnam (const char *dir = 0,
00388                  const char *pfx = 0);
00389 
00390 #if defined (ACE_HAS_WCHAR)
00391   ACE_NAMESPACE_INLINE_FUNCTION
00392   wchar_t *tempnam (const wchar_t *dir,
00393                     const wchar_t *pfx = 0);
00394 #endif /* ACE_HAS_WCHAR */
00395 
00396   ACE_NAMESPACE_INLINE_FUNCTION
00397   int vsprintf (char *buffer, const char *format, va_list argptr);
00398 
00399   ACE_NAMESPACE_INLINE_FUNCTION
00400   int vsnprintf (char *buffer, size_t maxlen, const char *format, va_list argptr);
00401 
00402 # if defined (ACE_HAS_WCHAR)
00403   ACE_NAMESPACE_INLINE_FUNCTION
00404   int vsprintf (wchar_t *buffer, const wchar_t *format, va_list argptr);
00405 
00406   ACE_NAMESPACE_INLINE_FUNCTION
00407   int vsnprintf (wchar_t *buffer, size_t maxlen, const wchar_t *format, va_list argptr);
00408 # endif /* ACE_HAS_WCHAR */
00409 
00410 } /* namespace ACE_OS */
00411 
00412 ACE_END_VERSIONED_NAMESPACE_DECL
00413 
00414 # if defined (ACE_HAS_INLINED_OSCALLS)
00415 #   if defined (ACE_INLINE)
00416 #     undef ACE_INLINE
00417 #   endif /* ACE_INLINE */
00418 #   define ACE_INLINE inline
00419 #   include "ace/OS_NS_stdio.inl"
00420 # endif /* ACE_HAS_INLINED_OSCALLS */
00421 
00422 # include /**/ "ace/post.h"
00423 #endif /* ACE_OS_NS_STDIO_H */

Generated on Thu Nov 9 09:41:57 2006 for ACE by doxygen 1.3.6