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

Last change on this file was 189, checked in by Herwig Bauernfeind, 16 years ago

Final fix for Ticket #88 (by diver)

  • 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#include <string.h>
27
28#include "smbwrp.h"
29
30// map errno errors to API errors
31int maperror(int rc)
32{
33 switch (rc)
34 {
35 case 0 : return NO_ERROR ; /* NO_ERROR */
36 case 1 : return ERROR_ACCESS_DENIED ; /* EPERM - Operation not permitted */
37 case 2 : return ERROR_FILE_NOT_FOUND ; /* ENOENT - No such file or directory */
38 case 3 : return ERROR_PID_MISMATCH ; /* ESRCH - No such process */
39 case 4 : return ERROR_INTERRUPT ; /* EINTR - Interrupted system call */
40 case 5 : return ERROR_READ_FAULT ; /* EIO - I/O error */
41 case 6 : return ERROR_BAD_UNIT ; /* ENXIO - No such device or address */
42 case 7 : return ERROR_INVALID_DATA ; /* E2BIG - Arguments or environment too big */
43 case 8 : return ERROR_BAD_EXE_FORMAT ; /* ENOEXEC - Invalid executable file format */
44 case 9 : return ERROR_INVALID_HANDLE ; /* EBADF - Bad file number */
45 case 10 : return ERROR_NO_CHILD_PROCESS ; /* ECHILD - No child processes */
46 case 11 : return ERROR_BUSY ; /* EAGAIN - Resource temporarily unavailable */
47 case 12 : return ERROR_NOT_ENOUGH_MEMORY ; /* ENOMEM - Not enough memory */
48 case 13 : return ERROR_ACCESS_DENIED ; /* EACCES - Permission denied */
49 case 14 : return ERROR_INVALID_ADDRESS ; /* EFAULT - Bad address */
50 case 15 : return ERROR_NOT_LOCKED ; /* ENOLCK - No locks available */
51 case 16 : return ERROR_BUSY ; /* EBUSY - Resource busy */
52 case 17 : return ERROR_FILE_EXISTS ; /* EEXIST - File exists */
53 case 18 : return ERROR_NOT_SAME_DEVICE ; /* EXDEV - Cross-device link */
54 case 19 : return ERROR_REM_NOT_LIST ; /* ENODEV - No such device */
55 case 20 : return ERROR_PATH_NOT_FOUND ; /* ENOTDIR - Not a directory */
56 case 21 : return ERROR_DIRECTORY ; /* EISDIR - Is a directory */
57 case 22 : return ERROR_INVALID_PARAMETER ; /* EINVAL - Invalid argument */
58 case 23 : return ERROR_TOO_MANY_OPEN_FILES ; /* ENFILE - Too many open files in system */
59 case 24 : return ERROR_TOO_MANY_OPENS ; /* EMFILE - Too many open files */
60 case 25 : return ERROR_MOD_NOT_FOUND ; /* ENOTTY - Inappropriate ioctl */
61 case 26 : return ERROR_LOCK_VIOLATION ; /* EDEADLK - Resource deadlock avoided */
62 case 27 : return ERROR_TRANSFER_TOO_LONG ; /* EFBIG - File too large */
63 case 28 : return ERROR_DISK_FULL ; /* ENOSPC - Disk full */
64 case 29 : return ERROR_SEEK ; /* ESPIPE - Invalid seek */
65 case 30 : return ERROR_WRITE_PROTECT ; /* EROFS - Read-only file system */
66 case 31 : return ERROR_TOO_MANY_OPEN_FILES ; /* EMLINK - Too many links */
67 case 32 : return ERROR_BROKEN_PIPE ; /* EPIPE - Broken pipe */
68 case 33 : return ERROR_INVALID_LEVEL ; /* EDOM - Domain error */
69 case 34 : return ERROR_FILENAME_EXCED_RANGE ; /* ERANGE - Result too large */
70 case 35 : return ERROR_DIR_NOT_EMPTY ; /* ENOTEMPTY - Directory not empty */
71 case 36 : return ERROR_BUSY_DRIVE ; /* EINPROGRESS - Operation now in progress */
72 case 37 : return ERROR_INVALID_FUNCTION ; /* ENOSYS - Function not implemented */
73 case 38 : return ERROR_FILENAME_EXCED_RANGE ; /* ENAMETOOLONG - File name too long */
74 case 39 : return ERROR_KBD_FOCUS_REQUIRED ; /* EDESTADDRREQ - Destination address required */
75 case 40 : return ERROR_TRANSFER_TOO_LONG ; /* EMSGSIZE - Message too long */
76 case 48 : return ERROR_NETWORK_BUSY ; /* EADDRINUSE - Address already in use */
77 case 49 : return ERROR_INFO_NOT_AVAIL ; /* EADDRNOTAVAIL - Can't assigned requested address */
78 case 50 : return ERROR_NETWORK_ACCESS_DENIED ; /* ENETDOWN - Network is down */
79 case 51 : return ERROR_NETWORK_ACCESS_DENIED ; /* ENETUNREACH - Network is unreachable */
80 case 52 : return ERROR_NETWORK_ACCESS_DENIED ; /* ENETRESET - Network dropped connection on reset */
81 case 53 : return ERROR_NETWORK_ACCESS_DENIED ; /* ECONNABORTED - Software caused connection abort */
82 case 54 : return ERROR_NETWORK_ACCESS_DENIED ; /* ECONNRESET - Connection reset by peer */
83 case 55 : return ERROR_BUFFER_OVERFLOW ; /* ENOBUFS - No buffer space available */
84 case 56 : return ERROR_PIPE_BUSY ; /* EISCONN - Socket is already connected */
85 case 57 : return ERROR_REM_NOT_LIST ; /* ENOTCONN - Socket is not connected */
86 case 58 : return ERROR_ALREADY_SHUTDOWN ; /* ESHUTDOWN - Can't send after socket shutdown */
87 case 60 : return ERROR_TIMEOUT ; /* ETIMEDOUT - Connection timed out */
88 case 61 : return ERROR_NETWORK_ACCESS_DENIED ; /* ECONNREFUSED - Connection refused */
89 case 63 : return ERROR_INVALID_BLOCK ; /* ENOTSOCK - Socket operation on non-socket */
90 case 64 : return ERROR_BAD_FORMAT ; /* EHOSTDOWN - Host is down */
91 case 65 : return ERROR_BAD_NETPATH ; /* EHOSTUNREACH - No route to host */
92 case 66 : return ERROR_BUSY_DRIVE ; /* EALREADY - Operation already in progress */
93 }
94// debug_printf( "Unhandled return code %d\n");
95 return rc + 40000;
96}
97
98char * getlastslash(char * path)
99{
100 char * p;
101 if (!path)
102 {
103 return NULL;
104 }
105 for (p = path + strlen(path) - 1; p >= path; p--)
106 {
107 if (*p == '\\' || *p == '/')
108 {
109 return p;
110 }
111 }
112 return NULL;
113}
114
Note: See TracBrowser for help on using the repository browser.