Synesis Software

unistd.h

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:    unistd.h
00003  *
00004  * Purpose: Declaration of various UNIX standard functions.
00005  *
00006  * Created: 1st November 2003
00007  * Updated: 13th May 2008
00008  *
00009  * Home:    http://synesis.com.au/software/
00010  *
00011  * Copyright (c) 2003-2008, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the names of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * ////////////////////////////////////////////////////////////////////////// */
00039 
00040 
00046 #ifndef SYNSOFT_UNIXEM_INCL_H_UNISTD
00047 #define SYNSOFT_UNIXEM_INCL_H_UNISTD
00048 
00049 #ifndef UNIXEM_DOCUMENTATION_SKIP_SECTION
00050 # define SYNSOFT_UNIXEM_VER_H_UNISTD_MAJOR      2
00051 # define SYNSOFT_UNIXEM_VER_H_UNISTD_MINOR      6
00052 # define SYNSOFT_UNIXEM_VER_H_UNISTD_REVISION   3
00053 # define SYNSOFT_UNIXEM_VER_H_UNISTD_EDIT       36
00054 #endif /* !UNIXEM_DOCUMENTATION_SKIP_SECTION */
00055 
00056 /* /////////////////////////////////////////////////////////////////////////////
00057  * Includes
00058  */
00059 
00060 #include <stddef.h>     /* for size_t */
00061 #include <sys/types.h>  /* for mode_t */
00062 
00063 /* Some of the functions declared here (and defined in unistd.c) may be
00064  * provided by some Win32 compilers. So we discriminate for support here,
00065  * and exclude definitions as appropriate.
00066  */
00067 
00068 #if defined(__BORLANDC__)
00069 # include <dir.h>
00070 # define UNIXEM_chdir_PROVIDED_BY_COMPILER
00071 # define UNIXEM_getcwd_PROVIDED_BY_COMPILER
00072 # define UNIXEM_mkdir_PROVIDED_BY_COMPILER
00073 # define UNIXEM_rmdir_PROVIDED_BY_COMPILER
00074 #elif defined(__DMC__)
00075 # include <direct.h>
00076 # define UNIXEM_chdir_PROVIDED_BY_COMPILER
00077 # define UNIXEM_close_PROVIDED_BY_COMPILER
00078 # define UNIXEM_getcwd_PROVIDED_BY_COMPILER
00079 # define UNIXEM_pid_t_PROVIDED_BY_COMPILER
00080 #elif defined(__GNUC__)
00081 # include <io.h>
00082 # define UNIXEM_chdir_PROVIDED_BY_COMPILER
00083 # define UNIXEM_chmod_PROVIDED_BY_COMPILER
00084 # define UNIXEM_getcwd_PROVIDED_BY_COMPILER
00085 # define UNIXEM_mkdir_PROVIDED_BY_COMPILER
00086 # ifndef _NO_OLDNAMES
00087 #  define UNIXEM_pid_t_PROVIDED_BY_COMPILER
00088 # endif /* !_NO_OLDNAMES */
00089 # define UNIXEM_rmdir_PROVIDED_BY_COMPILER
00090 #elif defined(__INTEL_COMPILER)
00091 # if defined(_WIN32) && \
00092      !defined(__STDC__)
00093 #  include <direct.h>
00094 #  define UNIXEM_chdir_PROVIDED_BY_COMPILER
00095 #  define UNIXEM_getcwd_PROVIDED_BY_COMPILER
00096 #  define UNIXEM_mkdir_PROVIDED_BY_COMPILER
00097 #  define UNIXEM_rmdir_PROVIDED_BY_COMPILER
00098 # endif /* !__STDC__ */
00099 #elif defined(__MWERKS__)
00100 # define UNIXEM_mkdir_PROVIDED_BY_COMPILER
00101 #elif defined(__WATCOMC__)
00102 # define UNIXEM_chdir_PROVIDED_BY_COMPILER
00103 # define UNIXEM_getcwd_PROVIDED_BY_COMPILER
00104 # define UNIXEM_mkdir_PROVIDED_BY_COMPILER
00105 # define UNIXEM_pid_t_PROVIDED_BY_COMPILER
00106 # define UNIXEM_rmdir_PROVIDED_BY_COMPILER
00107 #elif defined(_MSC_VER)
00108 # if !defined(__STDC__)
00109 #  include <direct.h>
00110 #  define UNIXEM_chdir_PROVIDED_BY_COMPILER
00111 #  define UNIXEM_getcwd_PROVIDED_BY_COMPILER
00112 #  define UNIXEM_mkdir_PROVIDED_BY_COMPILER
00113 #  define UNIXEM_rmdir_PROVIDED_BY_COMPILER
00114 #  include <stdio.h>
00115 #  define UNIXEM_unlink_PROVIDED_BY_COMPILER
00116 # endif /* !__STDC__ */
00117 #else
00118 # error Compiler not discriminated
00119 #endif /* compiler */
00120 
00121 
00122 #if defined(_MSC_VER) && \
00123     !defined(__STDC__)
00124 # define UNIXEM_UNISTD_INCLUDING_MS_DIRECT_H
00125 #endif /* compiler */
00126 
00127 /* ////////////////////////////////////////////////////////////////////////// */
00128 
00139 /* ////////////////////////////////////////////////////////////////////////// */
00140 
00141 #ifndef _WIN32
00142 # error This file is only currently defined for compilation on Win32 systems
00143 #endif /* _WIN32 */
00144 
00145 /* /////////////////////////////////////////////////////////////////////////////
00146  * Constants and definitions
00147  */
00148 
00149 //#ifndef PATH_MAX
00150 //# define PATH_MAX   (260)   /*!< \brief The maximum number of characters (including null terminator) in a directory entry name */
00151 //#endif /* !PATH_MAX */
00152 
00153 enum
00154 {
00155         _PC_LINK_MAX                    
00156     ,   _PC_MAX_CANON                   
00157     ,   _PC_MAX_INPUT                   
00158     ,   _PC_NAME_MAX                    
00159     ,   _PC_PATH_MAX                    
00161     ,   _PC_PIPE_BUF                    
00162     ,   _PC_CHOWN_RESTRICTED            
00163     ,   _PC_NO_TRUNC                    
00164     ,   _PC_VDISABLE                    
00165     ,   _PC_AIX_DISK_PARTITION          
00168     ,   _PC_AIX_DISK_SIZE               
00173     ,   _PC_FILESIZEBITS                
00174     ,   _PC_SYNC_IO                     
00176 #ifndef UNIXEM_DOCUMENTATION_SKIP_SECTION
00177 # define _PC_LINK_MAX               _PC_LINK_MAX
00178 # define _PC_MAX_CANON              _PC_MAX_CANON
00179 # define _PC_MAX_INPUT              _PC_MAX_INPUT
00180 # define _PC_NAME_MAX               _PC_NAME_MAX
00181 # define _PC_PATH_MAX               _PC_PATH_MAX
00182 # define _PC_PIPE_BUF               _PC_PIPE_BUF
00183 # define _PC_CHOWN_RESTRICTED       _PC_CHOWN_RESTRICTED
00184 # define _PC_NO_TRUNC               _PC_NO_TRUNC
00185 # define _PC_VDISABLE               _PC_VDISABLE
00186 # define _PC_AIX_DISK_PARTITION     _PC_AIX_DISK_PARTITION
00187 # define _PC_AIX_DISK_SIZE          _PC_AIX_DISK_SIZE
00188 # define _PC_FILESIZEBITS           _PC_FILESIZEBITS
00189 # define _PC_SYNC_IO                _PC_SYNC_IO
00190 #endif /* !UNIXEM_DOCUMENTATION_SKIP_SECTION */
00191 };
00192 
00193 /* /////////////////////////////////////////////////////////////////////////////
00194  * Typedefs
00195  */
00196 
00197 #if !defined(UNIXEM_pid_t_PROVIDED_BY_COMPILER) && \
00198     !defined(pid_t) && \
00199     !(  defined(_SCHED_H) && \
00200         defined(PTW32_DLLPORT))
00201 # define UNIXEM_pid_t_DEFINED
00202 typedef int         pid_t;
00203 #endif /* !UNIXEM_pid_t_PROVIDED_BY_COMPILER && !pid_t */
00204 
00205 /* /////////////////////////////////////////////////////////////////////////////
00206  * API functions
00207  */
00208 
00209 #ifdef __cplusplus
00210 extern "C" {
00211 #endif /* __cplusplus */
00212 
00225 int link(char const* originalFile, char const* linkName);
00226 
00233 #ifndef UNIXEM_unlink_PROVIDED_BY_COMPILER
00234 int unlink(char const* path);
00235 #endif /* !UNIXEM_unlink_PROVIDED_BY_COMPILER */
00236 
00237 
00246 #ifndef UNIXEM_chdir_PROVIDED_BY_COMPILER
00247 int chdir(char const* dirName);
00248 #endif /* !UNIXEM_chdir_PROVIDED_BY_COMPILER */
00249 
00250 
00260 #ifndef UNIXEM_getcwd_PROVIDED_BY_COMPILER
00261 char *getcwd(char *buffer, size_t max_len);
00262 #endif /* !UNIXEM_getcwd_PROVIDED_BY_COMPILER */
00263 
00264 
00274 #ifndef UNIXEM_mkdir_PROVIDED_BY_COMPILER
00275 int mkdir(char const* dirName, unsigned mode);
00276 #endif /* !UNIXEM_mkdir_PROVIDED_BY_COMPILER */
00277 
00278 
00286 #ifndef UNIXEM_rmdir_PROVIDED_BY_COMPILER
00287 int rmdir(char const* dirName);
00288 #endif /* !UNIXEM_rmdir_PROVIDED_BY_COMPILER */
00289 
00295 #ifndef UNIXEM_close_PROVIDED_BY_COMPILER
00296 int close(int handle);
00297 #endif /* !UNIXEM_close_PROVIDED_BY_COMPILER */
00298 
00299 /* * \brief Creates a pipe
00300  *
00301  * \param handles An array of two handles. handles[0] will be set to the
00302  * read stream. handles[1] will be set to the write stream
00303  * \return 0 on success, or -1 if there is an error
00304  */
00305 /* int pipe(int handles[2]); */
00306 
00309 int getpagesize(void);
00310 
00313 long pathconf(char const *path, int name);
00314 
00315 
00323 char *realpath(char const *path, char resolvedPath[]);
00324 
00329 int usleep(unsigned long microSeconds);
00330 
00331 
00334 pid_t getpid(void);
00335 
00336 
00345 #ifdef UNIXEM_DOCUMENTATION_SKIP_SECTION
00346 int gethostname(char* name, size_t cchName);
00347 #else /* ? UNIXEM_DOCUMENTATION_SKIP_SECTION */
00348 int unixem_gethostname(char* name, size_t cchName);
00349 # ifdef _WINSOCKAPI_
00350   /* already included, so we can redefine and do whatever we want/need */
00351 # else /* ? _WINSOCKAPI_ */
00352 #  define _WINSOCKAPI_ /* This will stop anyone else including it also */.
00353 # endif /* _WINSOCKAPI_ */
00354 # ifdef _WINSOCK2API_
00355 # else /* ? _WINSOCK2API_ */
00356 #  define _WINSOCK2API_
00357 # endif /* _WINSOCK2API_ */
00358 
00359 
00360 # ifdef __cplusplus
00361 inline int gethostname(char* name, size_t cchName)
00362 {
00363     return unixem_gethostname(name, cchName);
00364 }
00365 # endif /* __cplusplus */
00366 
00367 # define gethostname(name, cchName)     unixem_gethostname(name, cchName)
00368 #endif /* UNIXEM_DOCUMENTATION_SKIP_SECTION */
00369 
00370 #ifdef __cplusplus
00371 } /* extern "C" */
00372 #endif /* __cplusplus */
00373 
00374 /* ////////////////////////////////////////////////////////////////////////// */
00375 
00378 /* ////////////////////////////////////////////////////////////////////////// */
00379 
00380 #endif /* SYNSOFT_UNIXEM_INCL_H_UNISTD */
00381 
00382 /* ////////////////////////////////////////////////////////////////////////// */

UNIX Emulation for Win32 Libraries documentation © Synesis Software Pty Ltd, 2002-2007