Header And Logo

PostgreSQL
| The world's most advanced open source database.

win32error.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * win32error.c
00004  *    Map win32 error codes to errno values
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  *
00008  * IDENTIFICATION
00009  *    src/port/win32error.c
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 #ifndef FRONTEND
00015 #include "postgres.h"
00016 #else
00017 #include "postgres_fe.h"
00018 #endif
00019 
00020 static const struct
00021 {
00022     DWORD       winerr;
00023     int         doserr;
00024 }   doserrors[] =
00025 
00026 {
00027     {
00028         ERROR_INVALID_FUNCTION, EINVAL
00029     },
00030     {
00031         ERROR_FILE_NOT_FOUND, ENOENT
00032     },
00033     {
00034         ERROR_PATH_NOT_FOUND, ENOENT
00035     },
00036     {
00037         ERROR_TOO_MANY_OPEN_FILES, EMFILE
00038     },
00039     {
00040         ERROR_ACCESS_DENIED, EACCES
00041     },
00042     {
00043         ERROR_INVALID_HANDLE, EBADF
00044     },
00045     {
00046         ERROR_ARENA_TRASHED, ENOMEM
00047     },
00048     {
00049         ERROR_NOT_ENOUGH_MEMORY, ENOMEM
00050     },
00051     {
00052         ERROR_INVALID_BLOCK, ENOMEM
00053     },
00054     {
00055         ERROR_BAD_ENVIRONMENT, E2BIG
00056     },
00057     {
00058         ERROR_BAD_FORMAT, ENOEXEC
00059     },
00060     {
00061         ERROR_INVALID_ACCESS, EINVAL
00062     },
00063     {
00064         ERROR_INVALID_DATA, EINVAL
00065     },
00066     {
00067         ERROR_INVALID_DRIVE, ENOENT
00068     },
00069     {
00070         ERROR_CURRENT_DIRECTORY, EACCES
00071     },
00072     {
00073         ERROR_NOT_SAME_DEVICE, EXDEV
00074     },
00075     {
00076         ERROR_NO_MORE_FILES, ENOENT
00077     },
00078     {
00079         ERROR_LOCK_VIOLATION, EACCES
00080     },
00081     {
00082         ERROR_SHARING_VIOLATION, EACCES
00083     },
00084     {
00085         ERROR_BAD_NETPATH, ENOENT
00086     },
00087     {
00088         ERROR_NETWORK_ACCESS_DENIED, EACCES
00089     },
00090     {
00091         ERROR_BAD_NET_NAME, ENOENT
00092     },
00093     {
00094         ERROR_FILE_EXISTS, EEXIST
00095     },
00096     {
00097         ERROR_CANNOT_MAKE, EACCES
00098     },
00099     {
00100         ERROR_FAIL_I24, EACCES
00101     },
00102     {
00103         ERROR_INVALID_PARAMETER, EINVAL
00104     },
00105     {
00106         ERROR_NO_PROC_SLOTS, EAGAIN
00107     },
00108     {
00109         ERROR_DRIVE_LOCKED, EACCES
00110     },
00111     {
00112         ERROR_BROKEN_PIPE, EPIPE
00113     },
00114     {
00115         ERROR_DISK_FULL, ENOSPC
00116     },
00117     {
00118         ERROR_INVALID_TARGET_HANDLE, EBADF
00119     },
00120     {
00121         ERROR_INVALID_HANDLE, EINVAL
00122     },
00123     {
00124         ERROR_WAIT_NO_CHILDREN, ECHILD
00125     },
00126     {
00127         ERROR_CHILD_NOT_COMPLETE, ECHILD
00128     },
00129     {
00130         ERROR_DIRECT_ACCESS_HANDLE, EBADF
00131     },
00132     {
00133         ERROR_NEGATIVE_SEEK, EINVAL
00134     },
00135     {
00136         ERROR_SEEK_ON_DEVICE, EACCES
00137     },
00138     {
00139         ERROR_DIR_NOT_EMPTY, ENOTEMPTY
00140     },
00141     {
00142         ERROR_NOT_LOCKED, EACCES
00143     },
00144     {
00145         ERROR_BAD_PATHNAME, ENOENT
00146     },
00147     {
00148         ERROR_MAX_THRDS_REACHED, EAGAIN
00149     },
00150     {
00151         ERROR_LOCK_FAILED, EACCES
00152     },
00153     {
00154         ERROR_ALREADY_EXISTS, EEXIST
00155     },
00156     {
00157         ERROR_FILENAME_EXCED_RANGE, ENOENT
00158     },
00159     {
00160         ERROR_NESTING_NOT_ALLOWED, EAGAIN
00161     },
00162     {
00163         ERROR_NOT_ENOUGH_QUOTA, ENOMEM
00164     }
00165 };
00166 
00167 void
00168 _dosmaperr(unsigned long e)
00169 {
00170     int         i;
00171 
00172     if (e == 0)
00173     {
00174         errno = 0;
00175         return;
00176     }
00177 
00178     for (i = 0; i < lengthof(doserrors); i++)
00179     {
00180         if (doserrors[i].winerr == e)
00181         {
00182             errno = doserrors[i].doserr;
00183 #ifndef FRONTEND
00184             ereport(DEBUG5,
00185                     (errmsg_internal("mapped win32 error code %lu to %d",
00186                                      e, errno)));
00187 #elif FRONTEND_DEBUG
00188             fprintf(stderr, _("mapped win32 error code %lu to %d"), e, errno);
00189 #endif
00190             return;
00191         }
00192     }
00193 
00194 #ifndef FRONTEND
00195     ereport(LOG,
00196             (errmsg_internal("unrecognized win32 error code: %lu",
00197                              e)));
00198 #else
00199     fprintf(stderr, _("unrecognized win32 error code: %lu"), e);
00200 #endif
00201 
00202     errno = EINVAL;
00203     return;
00204 }