~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to mysys/my_winerr.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 MySQL AB, 2009 Sun Microsystems, Inc.
 
2
   Use is subject to license terms.
 
3
 
 
4
This program is free software; you can redistribute it and/or modify
 
5
it under the terms of the GNU General Public License as published by
 
6
the Free Software Foundation; version 2 of the License.
 
7
 
 
8
This program is distributed in the hope that it will be useful,
 
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
GNU General Public License for more details.
 
12
 
 
13
You should have received a copy of the GNU General Public License
 
14
along with this program; if not, write to the Free Software
 
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
16
 
 
17
/*
 
18
  Convert Windows API error (GetLastError() to Posix equivalent (errno)
 
19
  The exported function  my_osmaperr() is modelled after and borrows
 
20
  heavily from undocumented _dosmaperr()(found of the static Microsoft C runtime).
 
21
*/
 
22
 
 
23
#include <my_global.h>
 
24
#include <my_sys.h>
 
25
 
 
26
 
 
27
struct errentry 
 
28
{
 
29
  unsigned long oscode;   /* OS return value */
 
30
  int sysv_errno;  /* System V error code */
 
31
};
 
32
 
 
33
static struct errentry errtable[]= {
 
34
  {  ERROR_INVALID_FUNCTION,       EINVAL    },  /* 1 */
 
35
  {  ERROR_FILE_NOT_FOUND,         ENOENT    },  /* 2 */
 
36
  {  ERROR_PATH_NOT_FOUND,         ENOENT    },  /* 3 */
 
37
  {  ERROR_TOO_MANY_OPEN_FILES,    EMFILE    },  /* 4 */
 
38
  {  ERROR_ACCESS_DENIED,          EACCES    },  /* 5 */
 
39
  {  ERROR_INVALID_HANDLE,         EBADF     },  /* 6 */
 
40
  {  ERROR_ARENA_TRASHED,          ENOMEM    },  /* 7 */
 
41
  {  ERROR_NOT_ENOUGH_MEMORY,      ENOMEM    },  /* 8 */
 
42
  {  ERROR_INVALID_BLOCK,          ENOMEM    },  /* 9 */
 
43
  {  ERROR_BAD_ENVIRONMENT,        E2BIG     },  /* 10 */
 
44
  {  ERROR_BAD_FORMAT,             ENOEXEC   },  /* 11 */
 
45
  {  ERROR_INVALID_ACCESS,         EINVAL    },  /* 12 */
 
46
  {  ERROR_INVALID_DATA,           EINVAL    },  /* 13 */
 
47
  {  ERROR_INVALID_DRIVE,          ENOENT    },  /* 15 */
 
48
  {  ERROR_CURRENT_DIRECTORY,      EACCES    },  /* 16 */
 
49
  {  ERROR_NOT_SAME_DEVICE,        EXDEV     },  /* 17 */
 
50
  {  ERROR_NO_MORE_FILES,          ENOENT    },  /* 18 */
 
51
  {  ERROR_LOCK_VIOLATION,         EACCES    },  /* 33 */
 
52
  {  ERROR_BAD_NETPATH,            ENOENT    },  /* 53 */
 
53
  {  ERROR_NETWORK_ACCESS_DENIED,  EACCES    },  /* 65 */
 
54
  {  ERROR_BAD_NET_NAME,           ENOENT    },  /* 67 */
 
55
  {  ERROR_FILE_EXISTS,            EEXIST    },  /* 80 */
 
56
  {  ERROR_CANNOT_MAKE,            EACCES    },  /* 82 */
 
57
  {  ERROR_FAIL_I24,               EACCES    },  /* 83 */
 
58
  {  ERROR_INVALID_PARAMETER,      EINVAL    },  /* 87 */
 
59
  {  ERROR_NO_PROC_SLOTS,          EAGAIN    },  /* 89 */
 
60
  {  ERROR_DRIVE_LOCKED,           EACCES    },  /* 108 */
 
61
  {  ERROR_BROKEN_PIPE,            EPIPE     },  /* 109 */
 
62
  {  ERROR_DISK_FULL,              ENOSPC    },  /* 112 */
 
63
  {  ERROR_INVALID_TARGET_HANDLE,  EBADF     },  /* 114 */
 
64
  {  ERROR_INVALID_HANDLE,         EINVAL    },  /* 124 */
 
65
  {  ERROR_WAIT_NO_CHILDREN,       ECHILD    },  /* 128 */
 
66
  {  ERROR_CHILD_NOT_COMPLETE,     ECHILD    },  /* 129 */
 
67
  {  ERROR_DIRECT_ACCESS_HANDLE,   EBADF     },  /* 130 */
 
68
  {  ERROR_NEGATIVE_SEEK,          EINVAL    },  /* 131 */
 
69
  {  ERROR_SEEK_ON_DEVICE,         EACCES    },  /* 132 */
 
70
  {  ERROR_DIR_NOT_EMPTY,          ENOTEMPTY },  /* 145 */
 
71
  {  ERROR_NOT_LOCKED,             EACCES    },  /* 158 */
 
72
  {  ERROR_BAD_PATHNAME,           ENOENT    },  /* 161 */
 
73
  {  ERROR_MAX_THRDS_REACHED,      EAGAIN    },  /* 164 */
 
74
  {  ERROR_LOCK_FAILED,            EACCES    },  /* 167 */
 
75
  {  ERROR_ALREADY_EXISTS,         EEXIST    },  /* 183 */
 
76
  {  ERROR_FILENAME_EXCED_RANGE,   ENOENT    },  /* 206 */
 
77
  {  ERROR_NESTING_NOT_ALLOWED,    EAGAIN    },  /* 215 */
 
78
  {  ERROR_NOT_ENOUGH_QUOTA,       ENOMEM    }    /* 1816 */
 
79
};
 
80
 
 
81
/* size of the table */
 
82
#define ERRTABLESIZE (sizeof(errtable)/sizeof(errtable[0]))
 
83
 
 
84
/* The following two constants must be the minimum and maximum
 
85
values in the (contiguous) range of Exec Failure errors. */
 
86
#define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
 
87
#define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
 
88
 
 
89
/* These are the low and high value in the range of errors that are
 
90
access violations */
 
91
#define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
 
92
#define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
 
93
 
 
94
 
 
95
static int get_errno_from_oserr(unsigned long oserrno)
 
96
{
 
97
  int i;
 
98
 
 
99
  /* check the table for the OS error code */
 
100
  for (i= 0; i < ERRTABLESIZE; ++i) 
 
101
  {
 
102
    if (oserrno == errtable[i].oscode) 
 
103
    {
 
104
      return  errtable[i].sysv_errno;
 
105
    }
 
106
  }
 
107
 
 
108
  /* The error code wasn't in the table.  We check for a range of */
 
109
  /* EACCES errors or exec failure errors (ENOEXEC).  Otherwise   */
 
110
  /* EINVAL is returned.                                          */
 
111
 
 
112
  if (oserrno >= MIN_EACCES_RANGE && oserrno <= MAX_EACCES_RANGE)
 
113
    return EACCES;
 
114
  else if (oserrno >= MIN_EXEC_ERROR && oserrno <= MAX_EXEC_ERROR)
 
115
    return ENOEXEC;
 
116
  else
 
117
    return EINVAL;
 
118
}
 
119
 
 
120
/* Set errno corresponsing to GetLastError() value */
 
121
void my_osmaperr ( unsigned long oserrno)
 
122
{
 
123
    errno= get_errno_from_oserr(oserrno);
 
124
}