Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / osl / w32 / file_error.c
blob3bb2e49def9d015f4cc3015b053db410d1584a1f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #define UNICODE
21 #define _UNICODE
22 #include "systools/win32/uwinapi.h"
24 #include "file_error.h"
26 #include "osl/diagnose.h"
27 #include "osl/thread.h"
28 #include <sal/macros.h>
30 /* OS error to oslFileError values mapping table */
31 struct osl_file_error_entry
33 unsigned long oscode; /* OS return value */
34 int errnocode; /* oslFileError code */
37 static const struct osl_file_error_entry errtable[] = {
38 { ERROR_SUCCESS, osl_File_E_None }, /* 0 */
39 { ERROR_INVALID_FUNCTION, osl_File_E_INVAL }, /* 1 */
40 { ERROR_FILE_NOT_FOUND, osl_File_E_NOENT }, /* 2 */
41 { ERROR_PATH_NOT_FOUND, osl_File_E_NOENT }, /* 3 */
42 { ERROR_TOO_MANY_OPEN_FILES, osl_File_E_MFILE }, /* 4 */
43 { ERROR_ACCESS_DENIED, osl_File_E_ACCES }, /* 5 */
44 { ERROR_INVALID_HANDLE, osl_File_E_BADF }, /* 6 */
45 { ERROR_ARENA_TRASHED, osl_File_E_NOMEM }, /* 7 */
46 { ERROR_NOT_ENOUGH_MEMORY, osl_File_E_NOMEM }, /* 8 */
47 { ERROR_INVALID_BLOCK, osl_File_E_NOMEM }, /* 9 */
48 { ERROR_BAD_ENVIRONMENT, osl_File_E_2BIG }, /* 10 */
49 { ERROR_BAD_FORMAT, osl_File_E_NOEXEC }, /* 11 */
50 { ERROR_INVALID_ACCESS, osl_File_E_INVAL }, /* 12 */
51 { ERROR_INVALID_DATA, osl_File_E_INVAL }, /* 13 */
52 { ERROR_INVALID_DRIVE, osl_File_E_NOENT }, /* 15 */
53 { ERROR_CURRENT_DIRECTORY, osl_File_E_ACCES }, /* 16 */
54 { ERROR_NOT_SAME_DEVICE, osl_File_E_XDEV }, /* 17 */
55 { ERROR_NO_MORE_FILES, osl_File_E_NOENT }, /* 18 */
56 { ERROR_NOT_READY, osl_File_E_NOTREADY }, /* 21 */
57 { ERROR_SHARING_VIOLATION, osl_File_E_ACCES }, /* 32 */
58 { ERROR_LOCK_VIOLATION, osl_File_E_ACCES }, /* 33 */
59 { ERROR_BAD_NETPATH, osl_File_E_NOENT }, /* 53 */
60 { ERROR_NETWORK_ACCESS_DENIED, osl_File_E_ACCES }, /* 65 */
61 { ERROR_BAD_NET_NAME, osl_File_E_NOENT }, /* 67 */
62 { ERROR_FILE_EXISTS, osl_File_E_EXIST }, /* 80 */
63 { ERROR_CANNOT_MAKE, osl_File_E_ACCES }, /* 82 */
64 { ERROR_FAIL_I24, osl_File_E_ACCES }, /* 83 */
65 { ERROR_INVALID_PARAMETER, osl_File_E_INVAL }, /* 87 */
66 { ERROR_NO_PROC_SLOTS, osl_File_E_AGAIN }, /* 89 */
67 { ERROR_DRIVE_LOCKED, osl_File_E_ACCES }, /* 108 */
68 { ERROR_BROKEN_PIPE, osl_File_E_PIPE }, /* 109 */
69 { ERROR_DISK_FULL, osl_File_E_NOSPC }, /* 112 */
70 { ERROR_INVALID_TARGET_HANDLE, osl_File_E_BADF }, /* 114 */
71 { ERROR_INVALID_HANDLE, osl_File_E_INVAL }, /* 124 */
72 { ERROR_WAIT_NO_CHILDREN, osl_File_E_CHILD }, /* 128 */
73 { ERROR_CHILD_NOT_COMPLETE, osl_File_E_CHILD }, /* 129 */
74 { ERROR_DIRECT_ACCESS_HANDLE, osl_File_E_BADF }, /* 130 */
75 { ERROR_NEGATIVE_SEEK, osl_File_E_INVAL }, /* 131 */
76 { ERROR_SEEK_ON_DEVICE, osl_File_E_ACCES }, /* 132 */
77 { ERROR_DIR_NOT_EMPTY, osl_File_E_NOTEMPTY }, /* 145 */
78 { ERROR_NOT_LOCKED, osl_File_E_ACCES }, /* 158 */
79 { ERROR_BAD_PATHNAME, osl_File_E_NOENT }, /* 161 */
80 { ERROR_MAX_THRDS_REACHED, osl_File_E_AGAIN }, /* 164 */
81 { ERROR_LOCK_FAILED, osl_File_E_ACCES }, /* 167 */
82 { ERROR_ALREADY_EXISTS, osl_File_E_EXIST }, /* 183 */
83 { ERROR_FILENAME_EXCED_RANGE, osl_File_E_NOENT }, /* 206 */
84 { ERROR_NESTING_NOT_ALLOWED, osl_File_E_AGAIN }, /* 215 */
85 { ERROR_DIRECTORY, osl_File_E_NOENT }, /* 267 */
86 { ERROR_NOT_ENOUGH_QUOTA, osl_File_E_NOMEM }, /* 1816 */
87 { ERROR_UNEXP_NET_ERR, osl_File_E_NETWORK } /* 59 */
90 /* The following two constants must be the minimum and maximum
91 values in the (contiguous) range of osl_File_E_xec Failure errors.
93 #define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
94 #define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
96 /* These are the low and high value in the range of errors that are
97 access violations
99 #define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
100 #define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
102 oslFileError oslTranslateFileError (/*DWORD*/ unsigned long dwError)
104 static const int n = SAL_N_ELEMENTS(errtable);
106 int i;
107 for (i = 0; i < n; ++i )
109 if (dwError == errtable[i].oscode)
110 return (oslFileError)(errtable[i].errnocode);
113 /* The error code wasn't in the table. We check for a range of
114 osl_File_E_ACCES errors or exec failure errors (ENOEXEC).
115 Otherwise osl_File_E_INVAL is returned.
117 if ( (dwError >= MIN_EACCES_RANGE) && (dwError <= MAX_EACCES_RANGE) )
118 return osl_File_E_ACCES;
119 else if ( (dwError >= MIN_EXEC_ERROR) && (dwError <= MAX_EXEC_ERROR) )
120 return osl_File_E_NOEXEC;
121 else
122 return osl_File_E_INVAL;
125 //#####################################################
126 #if OSL_DEBUG_LEVEL > 0
127 void _osl_warnFile( const char *message, rtl_uString *ustrFile )
129 char szBuffer[2048];
131 if (ustrFile)
133 rtl_String *strFile = NULL;
135 rtl_uString2String( &strFile, rtl_uString_getStr( ustrFile ), rtl_uString_getLength( ustrFile ),
136 osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
137 snprintf( szBuffer, sizeof(szBuffer), message, strFile->buffer );
138 rtl_string_release( strFile );
140 message = szBuffer;
142 OSL_FAIL( message );
144 #endif /* OSL_DEBUG_LEVEL */
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */