1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define INCL_DOSERRORS
18#include "apr_arch_file_io.h"
19#include "apr_file_io.h"
20#include <errno.h>
21#include <string.h>
22#include "apr_errno.h"
23
24static int errormap[][2] = {
25    { NO_ERROR,                   APR_SUCCESS      },
26    { ERROR_FILE_NOT_FOUND,       APR_ENOENT       },
27    { ERROR_PATH_NOT_FOUND,       APR_ENOENT       },
28    { ERROR_TOO_MANY_OPEN_FILES,  APR_EMFILE       },
29    { ERROR_ACCESS_DENIED,        APR_EACCES       },
30    { ERROR_SHARING_VIOLATION,    APR_EACCES       },
31    { ERROR_INVALID_PARAMETER,    APR_EINVAL       },
32    { ERROR_OPEN_FAILED,          APR_ENOENT       },
33    { ERROR_DISK_FULL,            APR_ENOSPC       },
34    { ERROR_FILENAME_EXCED_RANGE, APR_ENAMETOOLONG },
35    { ERROR_INVALID_FUNCTION,     APR_EINVAL       },
36    { ERROR_INVALID_HANDLE,       APR_EBADF        },
37    { ERROR_NEGATIVE_SEEK,        APR_ESPIPE       },
38    { ERROR_NO_SIGNAL_SENT,       ESRCH            },
39    { ERROR_NO_DATA,              APR_EAGAIN       },
40    { SOCEINTR,                 EINTR           },
41    { SOCEWOULDBLOCK,           EWOULDBLOCK     },
42    { SOCEINPROGRESS,           EINPROGRESS     },
43    { SOCEALREADY,              EALREADY        },
44    { SOCENOTSOCK,              ENOTSOCK        },
45    { SOCEDESTADDRREQ,          EDESTADDRREQ    },
46    { SOCEMSGSIZE,              EMSGSIZE        },
47    { SOCEPROTOTYPE,            EPROTOTYPE      },
48    { SOCENOPROTOOPT,           ENOPROTOOPT     },
49    { SOCEPROTONOSUPPORT,       EPROTONOSUPPORT },
50    { SOCESOCKTNOSUPPORT,       ESOCKTNOSUPPORT },
51    { SOCEOPNOTSUPP,            EOPNOTSUPP      },
52    { SOCEPFNOSUPPORT,          EPFNOSUPPORT    },
53    { SOCEAFNOSUPPORT,          EAFNOSUPPORT    },
54    { SOCEADDRINUSE,            EADDRINUSE      },
55    { SOCEADDRNOTAVAIL,         EADDRNOTAVAIL   },
56    { SOCENETDOWN,              ENETDOWN        },
57    { SOCENETUNREACH,           ENETUNREACH     },
58    { SOCENETRESET,             ENETRESET       },
59    { SOCECONNABORTED,          ECONNABORTED    },
60    { SOCECONNRESET,            ECONNRESET      },
61    { SOCENOBUFS,               ENOBUFS         },
62    { SOCEISCONN,               EISCONN         },
63    { SOCENOTCONN,              ENOTCONN        },
64    { SOCESHUTDOWN,             ESHUTDOWN       },
65    { SOCETOOMANYREFS,          ETOOMANYREFS    },
66    { SOCETIMEDOUT,             ETIMEDOUT       },
67    { SOCECONNREFUSED,          ECONNREFUSED    },
68    { SOCELOOP,                 ELOOP           },
69    { SOCENAMETOOLONG,          ENAMETOOLONG    },
70    { SOCEHOSTDOWN,             EHOSTDOWN       },
71    { SOCEHOSTUNREACH,          EHOSTUNREACH    },
72    { SOCENOTEMPTY,             ENOTEMPTY       },
73    { SOCEPIPE,                 EPIPE           }
74};
75
76#define MAPSIZE (sizeof(errormap)/sizeof(errormap[0]))
77
78int apr_canonical_error(apr_status_t err)
79{
80    int rv = -1, index;
81
82    if (err < APR_OS_START_SYSERR)
83        return err;
84
85    err -= APR_OS_START_SYSERR;
86
87    for (index=0; index<MAPSIZE && errormap[index][0] != err; index++);
88
89    if (index<MAPSIZE)
90        rv = errormap[index][1];
91    else
92        fprintf(stderr, "apr_canonical_error: Unknown OS/2 error code %d\n", err );
93
94    return rv;
95}
96