source: branches/client-1.5/src/util.c@ 168

Last change on this file since 168 was 151, checked in by Yuri Dario, 17 years ago

Added proper license informations, .def cleaning.

  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
1/*
2 Netdrive Samba client plugin
3 general utility functions
4 Copyright (C) netlabs.org 2003-2008
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#define INCL_DOS
22#define INCL_DOSERRORS
23#include <os2.h>
24#include <errno.h>
25#include <stdlib.h>
26
27#include "smbwrp.h"
28
29// map errno errors to API errors
30int maperror(int rc)
31{
32 switch (rc)
33 {
34 case 0 : return NO_ERROR ; /* NO_ERROR */
35 case 1 : return ERROR_ACCESS_DENIED ; /* EPERM - Operation not permitted */
36 case 2 : return ERROR_FILE_NOT_FOUND ; /* ENOENT - No such file or directory */
37 case 3 : return ERROR_PID_MISMATCH ; /* ESRCH - No such process */
38 case 4 : return ERROR_INTERRUPT ; /* EINTR - Interrupted system call */
39 case 5 : return ERROR_READ_FAULT ; /* EIO - I/O error */
40 case 6 : return ERROR_BAD_UNIT ; /* ENXIO - No such device or address */
41 case 7 : return ERROR_INVALID_DATA ; /* E2BIG - Arguments or environment too big */
42 case 8 : return ERROR_BAD_EXE_FORMAT ; /* ENOEXEC - Invalid executable file format */
43 case 9 : return ERROR_INVALID_HANDLE ; /* EBADF - Bad file number */
44 case 10 : return ERROR_NO_CHILD_PROCESS ; /* ECHILD - No child processes */
45 case 11 : return ERROR_BUSY ; /* EAGAIN - Resource temporarily unavailable */
46 case 12 : return ERROR_NOT_ENOUGH_MEMORY ; /* ENOMEM - Not enough memory */
47 case 13 : return ERROR_ACCESS_DENIED ; /* EACCES - Permission denied */
48 case 14 : return ERROR_INVALID_ADDRESS ; /* EFAULT - Bad address */
49 case 15 : return ERROR_NOT_LOCKED ; /* ENOLCK - No locks available */
50 case 16 : return ERROR_BUSY ; /* EBUSY - Resource busy */
51 case 17 : return ERROR_FILE_EXISTS ; /* EEXIST - File exists */
52 case 18 : return ERROR_NOT_SAME_DEVICE ; /* EXDEV - Cross-device link */
53 case 19 : return ERROR_REM_NOT_LIST ; /* ENODEV - No such device */
54 case 20 : return ERROR_PATH_NOT_FOUND ; /* ENOTDIR - Not a directory */
55 case 21 : return ERROR_DIRECTORY ; /* EISDIR - Is a directory */
56 case 22 : return ERROR_INVALID_PARAMETER ; /* EINVAL - Invalid argument */
57 case 23 : return ERROR_TOO_MANY_OPEN_FILES ; /* ENFILE - Too many open files in system */
58 case 24 : return ERROR_TOO_MANY_OPENS ; /* EMFILE - Too many open files */
59 case 25 : return ERROR_MOD_NOT_FOUND ; /* ENOTTY - Inappropriate ioctl */
60 case 26 : return ERROR_LOCK_VIOLATION ; /* EDEADLK - Resource deadlock avoided */
61 case 27 : return ERROR_TRANSFER_TOO_LONG ; /* EFBIG - File too large */
62 case 28 : return ERROR_DISK_FULL ; /* ENOSPC - Disk full */
63 case 29 : return ERROR_SEEK ; /* ESPIPE - Invalid seek */
64 case 30 : return ERROR_WRITE_PROTECT ; /* EROFS - Read-only file system */
65 case 31 : return ERROR_TOO_MANY_OPEN_FILES ; /* EMLINK - Too many links */
66 case 32 : return ERROR_BROKEN_PIPE ; /* EPIPE - Broken pipe */
67 case 33 : return ERROR_INVALID_LEVEL ; /* EDOM - Domain error */
68 case 34 : return ERROR_FILENAME_EXCED_RANGE ; /* ERANGE - Result too large */
69 case 35 : return ERROR_DIR_NOT_EMPTY ; /* ENOTEMPTY - Directory not empty */
70 case 36 : return ERROR_BUSY_DRIVE ; /* EINPROGRESS - Operation now in progress */
71 case 37 : return ERROR_INVALID_FUNCTION ; /* ENOSYS - Function not implemented */
72 case 38 : return ERROR_FILENAME_EXCED_RANGE ; /* ENAMETOOLONG - File name too long */
73 case 39 : return ERROR_KBD_FOCUS_REQUIRED ; /* EDESTADDRREQ - Destination address required */
74 case 40 : return ERROR_TRANSFER_TOO_LONG ; /* EMSGSIZE - Message too long */
75 case 48 : return ERROR_NETWORK_BUSY ; /* EADDRINUSE - Address already in use */
76 case 49 : return ERROR_INFO_NOT_AVAIL ; /* EADDRNOTAVAIL - Can't assigned requested address */
77 case 50 : return ERROR_NETWORK_ACCESS_DENIED ; /* ENETDOWN - Network is down */
78 case 51 : return ERROR_NETWORK_ACCESS_DENIED ; /* ENETUNREACH - Network is unreachable */
79 case 52 : return ERROR_NETWORK_ACCESS_DENIED ; /* ENETRESET - Network dropped connection on reset */
80 case 53 : return ERROR_NETWORK_ACCESS_DENIED ; /* ECONNABORTED - Software caused connection abort */
81 case 54 : return ERROR_NETWORK_ACCESS_DENIED ; /* ECONNRESET - Connection reset by peer */
82 case 55 : return ERROR_BUFFER_OVERFLOW ; /* ENOBUFS - No buffer space available */
83 case 56 : return ERROR_PIPE_BUSY ; /* EISCONN - Socket is already connected */
84 case 57 : return ERROR_REM_NOT_LIST ; /* ENOTCONN - Socket is not connected */
85 case 58 : return ERROR_ALREADY_SHUTDOWN ; /* ESHUTDOWN - Can't send after socket shutdown */
86 case 60 : return ERROR_TIMEOUT ; /* ETIMEDOUT - Connection timed out */
87 case 61 : return ERROR_NETWORK_ACCESS_DENIED ; /* ECONNREFUSED - Connection refused */
88 case 63 : return ERROR_INVALID_BLOCK ; /* ENOTSOCK - Socket operation on non-socket */
89 case 64 : return ERROR_BAD_FORMAT ; /* EHOSTDOWN - Host is down */
90 case 65 : return ERROR_BAD_NETPATH ; /* EHOSTUNREACH - No route to host */
91 case 66 : return ERROR_BUSY_DRIVE ; /* EALREADY - Operation already in progress */
92 }
93 debug_printf( "Unhandled return code %d\n");
94 return rc + 40000;
95}
96
97char * getlastslash(char * path)
98{
99 char * p;
100 if (!path)
101 {
102 return NULL;
103 }
104 for (p = path + strlen(path) - 1; p >= path; p--)
105 {
106 if (*p == '\\' || *p == '/')
107 {
108 return p;
109 }
110 }
111 return NULL;
112}
113
Note: See TracBrowser for help on using the repository browser.