move SK_DISABLE_DITHER_32BIT_GRADIENT from SkUserConfig.h to skia.gyp, so we can...
[chromium-blink-merge.git] / net / base / net_errors_posix.cc
blob0d8b7de34471895bca3d3ec527e70e4e01130475
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/base/net_errors.h"
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <string>
10 #include <unistd.h>
12 #include "base/logging.h"
13 #include "base/stringprintf.h"
15 namespace net {
17 Error MapSystemError(int os_error) {
18 if (os_error != 0)
19 DVLOG(2) << "Error " << os_error;
21 // There are numerous posix error codes, but these are the ones we thus far
22 // find interesting.
23 switch (os_error) {
24 case EAGAIN:
25 #if EWOULDBLOCK != EAGAIN
26 case EWOULDBLOCK:
27 #endif
28 return ERR_IO_PENDING;
29 case EACCES:
30 return ERR_ACCESS_DENIED;
31 case ENETDOWN:
32 return ERR_INTERNET_DISCONNECTED;
33 case ETIMEDOUT:
34 return ERR_TIMED_OUT;
35 case ECONNRESET:
36 case ENETRESET: // Related to keep-alive.
37 case EPIPE:
38 return ERR_CONNECTION_RESET;
39 case ECONNABORTED:
40 return ERR_CONNECTION_ABORTED;
41 case ECONNREFUSED:
42 return ERR_CONNECTION_REFUSED;
43 case EHOSTUNREACH:
44 case EHOSTDOWN:
45 case ENETUNREACH:
46 case EAFNOSUPPORT:
47 return ERR_ADDRESS_UNREACHABLE;
48 case EADDRNOTAVAIL:
49 return ERR_ADDRESS_INVALID;
50 case EMSGSIZE:
51 return ERR_MSG_TOO_BIG;
52 case ENOTCONN:
53 return ERR_SOCKET_NOT_CONNECTED;
54 case EINVAL:
55 return ERR_INVALID_ARGUMENT;
56 case EADDRINUSE:
57 return ERR_ADDRESS_IN_USE;
58 case E2BIG: // Argument list too long.
59 return ERR_INVALID_ARGUMENT;
60 case EBADF: // Bad file descriptor.
61 return ERR_INVALID_HANDLE;
62 case EBUSY: // Device or resource busy.
63 return ERR_INSUFFICIENT_RESOURCES;
64 case ECANCELED: // Operation canceled.
65 return ERR_ABORTED;
66 case EDEADLK: // Resource deadlock avoided.
67 return ERR_INSUFFICIENT_RESOURCES;
68 case EDQUOT: // Disk quota exceeded.
69 return ERR_FILE_NO_SPACE;
70 case EEXIST: // File exists.
71 return ERR_FILE_EXISTS;
72 case EFAULT: // Bad address.
73 return ERR_INVALID_ARGUMENT;
74 case EFBIG: // File too large.
75 return ERR_FILE_TOO_BIG;
76 case EISDIR: // Is a directory.
77 return ERR_FILE_NOT_FOUND;
78 case ENAMETOOLONG: // Filename too long.
79 return ERR_FILE_PATH_TOO_LONG;
80 case ENFILE: // Too many open files in system.
81 return ERR_INSUFFICIENT_RESOURCES;
82 case ENOBUFS: // No buffer space available.
83 return ERR_OUT_OF_MEMORY;
84 case ENODEV: // No such device.
85 return ERR_INVALID_ARGUMENT;
86 case ENOENT: // No such file or directory.
87 return ERR_FILE_NOT_FOUND;
88 case ENOLCK: // No locks available.
89 return ERR_INSUFFICIENT_RESOURCES;
90 case ENOMEM: // Not enough space.
91 return ERR_OUT_OF_MEMORY;
92 case ENOSPC: // No space left on device.
93 return ERR_FILE_NO_SPACE;
94 case ENOSYS: // Function not implemented.
95 return ERR_NOT_IMPLEMENTED;
96 case ENOTDIR: // Not a directory.
97 return ERR_FILE_NOT_FOUND;
98 case ENOTSUP: // Operation not supported.
99 return ERR_NOT_IMPLEMENTED;
100 case EPERM: // Operation not permitted.
101 return ERR_ACCESS_DENIED;
102 case EROFS: // Read-only file system.
103 return ERR_ACCESS_DENIED;
104 case ETXTBSY: // Text file busy.
105 return ERR_ACCESS_DENIED;
106 case EUSERS: // Too many users.
107 return ERR_INSUFFICIENT_RESOURCES;
108 case EMFILE: // Too many open files.
109 return ERR_INSUFFICIENT_RESOURCES;
111 case 0:
112 return OK;
113 default:
114 LOG(WARNING) << "Unknown error " << os_error
115 << " mapped to net::ERR_FAILED";
116 return ERR_FAILED;
120 } // namespace net