source: trunk/client/src/util.c@ 958

Last change on this file since 958 was 957, checked in by Silvan Scherrer, 9 years ago

samba client: adjust copyright

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