~ubuntu-branches/ubuntu/saucy/nspr/saucy-updates

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/md/windows/w95io.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-08-10 11:34:26 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090810113426-3uv4diflrkcbdimm
Tags: 4.8-0ubuntu1
* New upstream release: 4.8 (LP: #387812)
* adjust patches to changed upstreanm codebase
  - update debian/patches/99_configure.patch
* update shlibs symbols to include new API elements
  - update debian/libnspr4-0d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include <wchar.h>
50
50
#endif /* MOZ_UNICODE */
51
51
 
 
52
#ifdef WINCE
 
53
 
 
54
static HANDLE CreateFileA(LPCSTR lpFileName,
 
55
                          DWORD dwDesiredAccess,
 
56
                          DWORD dwShareMode,
 
57
                          LPSECURITY_ATTRIBUTES lpSecurityAttributes,
 
58
                          DWORD dwCreationDisposition,
 
59
                          DWORD dwFlagsAndAttributes,
 
60
                          HANDLE hTemplateFile)
 
61
{
 
62
    PRUnichar wFileName[MAX_PATH];
 
63
    MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH);
 
64
    return CreateFileW(wFileName, dwDesiredAccess, dwShareMode,
 
65
                       lpSecurityAttributes, dwCreationDisposition,
 
66
                       dwFlagsAndAttributes, hTemplateFile);
 
67
}
 
68
 
 
69
/*
 
70
 * We seem to call FindFirstFileA and FindNextFileA just to get
 
71
 * the file names in a directory listing.  If so, we could define
 
72
 * a custom WIN32_FIND_DATAA structure with just the cFileName
 
73
 * member, and the CopyFindFileDataW2A function could just
 
74
 * copy/convert the cFileName member.
 
75
 */
 
76
static void CopyFindFileDataW2A(LPWIN32_FIND_DATAW from,
 
77
                                LPWIN32_FIND_DATAA to)
 
78
{
 
79
    /*
 
80
     * WIN32_FIND_DATAA and WIN32_FIND_DATAW are slightly different.
 
81
     * The dwReserved0, dwReserved1, and cAlternateFileName members
 
82
     * exist only in WIN32_FIND_DATAA.  The dwOID member exists only
 
83
     * in WIN32_FIND_DATAW.
 
84
     */
 
85
    to->dwFileAttributes = from->dwFileAttributes;
 
86
    to->ftCreationTime = from->ftCreationTime;
 
87
    to->ftLastAccessTime = from->ftLastAccessTime;
 
88
    to->ftLastWriteTime = from->ftLastWriteTime;
 
89
    to->nFileSizeHigh = from->nFileSizeHigh;
 
90
    to->nFileSizeLow = from->nFileSizeLow;
 
91
    to->dwReserved0 = 0;
 
92
    to->dwReserved1 = 0;
 
93
    WideCharToMultiByte(CP_ACP, 0, from->cFileName, -1,
 
94
                        to->cFileName, MAX_PATH, NULL, NULL);
 
95
    to->cAlternateFileName[0] = '\0';
 
96
}
 
97
 
 
98
static HANDLE FindFirstFileA(LPCSTR lpFileName,
 
99
                             LPWIN32_FIND_DATAA lpFindFileData)
 
100
{
 
101
    PRUnichar wFileName[MAX_PATH];
 
102
    HANDLE hFindFile;
 
103
    WIN32_FIND_DATAW wFindFileData;
 
104
    
 
105
    MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH);
 
106
    hFindFile = FindFirstFileW(wFileName, &wFindFileData);
 
107
    if (hFindFile != INVALID_HANDLE_VALUE) {
 
108
        CopyFindFileDataW2A(&wFindFileData, lpFindFileData);
 
109
    }
 
110
    return hFindFile;
 
111
}
 
112
 
 
113
static BOOL FindNextFileA(HANDLE hFindFile,
 
114
                          LPWIN32_FIND_DATAA lpFindFileData)
 
115
{
 
116
    WIN32_FIND_DATAW wFindFileData;
 
117
    BOOL rv;
 
118
 
 
119
    rv = FindNextFileW(hFindFile, &wFindFileData);
 
120
    if (rv) {
 
121
        CopyFindFileDataW2A(&wFindFileData, lpFindFileData);
 
122
    }
 
123
    return rv;
 
124
}
 
125
 
 
126
static BOOL GetFileAttributesExA(LPCSTR lpFileName,
 
127
                                 GET_FILEEX_INFO_LEVELS fInfoLevelId,
 
128
                                 LPVOID lpFileInformation)
 
129
{
 
130
    PRUnichar wFileName[MAX_PATH];
 
131
    MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH);
 
132
    return GetFileAttributesExW(wFileName, fInfoLevelId, lpFileInformation);
 
133
}
 
134
 
 
135
static BOOL DeleteFileA(LPCSTR lpFileName)
 
136
{
 
137
    PRUnichar wFileName[MAX_PATH];
 
138
    MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH);
 
139
    return DeleteFileW(wFileName);
 
140
}
 
141
 
 
142
static BOOL MoveFileA(LPCSTR from, LPCSTR to)
 
143
{
 
144
    PRUnichar wFrom[MAX_PATH];
 
145
    PRUnichar wTo[MAX_PATH];
 
146
    MultiByteToWideChar(CP_ACP, 0, from, -1, wFrom, MAX_PATH);
 
147
    MultiByteToWideChar(CP_ACP, 0, to, -1, wTo, MAX_PATH);
 
148
    return MoveFileW(wFrom, wTo);
 
149
}
 
150
 
 
151
static BOOL CreateDirectoryA(LPCSTR lpPathName,
 
152
                             LPSECURITY_ATTRIBUTES lpSecurityAttributes)
 
153
{
 
154
    PRUnichar wPathName[MAX_PATH];
 
155
    MultiByteToWideChar(CP_ACP, 0, lpPathName, -1, wPathName, MAX_PATH);
 
156
    return CreateDirectoryW(wPathName, lpSecurityAttributes);
 
157
}
 
158
 
 
159
static BOOL RemoveDirectoryA(LPCSTR lpPathName)
 
160
{
 
161
    PRUnichar wPathName[MAX_PATH];
 
162
    MultiByteToWideChar(CP_ACP, 0, lpPathName, -1, wPathName, MAX_PATH);
 
163
    return RemoveDirectoryW(wPathName);
 
164
}
 
165
 
 
166
static long GetDriveType(const char *lpRootPathName)
 
167
{
 
168
    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
 
169
    return 0; // The drive type cannot be determined.
 
170
}
 
171
 
 
172
static DWORD GetFullPathName(const char *lpFileName,
 
173
                             DWORD nBufferLength,
 
174
                             const char *lpBuffer,
 
175
                             const char **lpFilePart)
 
176
{
 
177
    // needs work dft
 
178
    DWORD len = strlen(lpFileName);
 
179
    if (len > nBufferLength)
 
180
        return len;
 
181
  
 
182
    strncpy((char *)lpBuffer, lpFileName, len);
 
183
    ((char *)lpBuffer)[len] = '\0';
 
184
  
 
185
    if (lpFilePart) {
 
186
        char *sep = strrchr(lpBuffer, '\\');
 
187
        if (sep) {
 
188
            sep++; // pass the seperator
 
189
            *lpFilePart = sep;
 
190
        } else {
 
191
            *lpFilePart = lpBuffer;
 
192
        }
 
193
    }
 
194
    return len;
 
195
}
 
196
 
 
197
static BOOL LockFile(HANDLE hFile,
 
198
                     DWORD dwFileOffsetLow,
 
199
                     DWORD dwFileOffsetHigh,
 
200
                     DWORD nNumberOfBytesToLockLow,
 
201
                     DWORD nNumberOfBytesToLockHigh)
 
202
{
 
203
    OVERLAPPED overlapped = {0};
 
204
    overlapped.Offset = dwFileOffsetLow;
 
205
    overlapped.OffsetHigh = dwFileOffsetHigh;
 
206
    return LockFileEx(hFile,
 
207
                      LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY,
 
208
                      0, // reserved
 
209
                      nNumberOfBytesToLockLow,
 
210
                      nNumberOfBytesToLockHigh, &overlapped);
 
211
}
 
212
 
 
213
static BOOL UnlockFile(HANDLE hFile,
 
214
                       DWORD dwFileOffsetLow,
 
215
                       DWORD dwFileOffsetHigh,
 
216
                       DWORD nNumberOfBytesToUnlockLow,
 
217
                       DWORD nNumberOfBytesToUnlockHigh)
 
218
{
 
219
    OVERLAPPED overlapped = {0};
 
220
    overlapped.Offset = dwFileOffsetLow;
 
221
    overlapped.OffsetHigh = dwFileOffsetHigh;
 
222
    return UnlockFileEx(hFile,
 
223
                        0, // reserved
 
224
                        nNumberOfBytesToUnlockLow,
 
225
                        nNumberOfBytesToUnlockHigh, &overlapped);
 
226
}
 
227
 
 
228
static unsigned char *_mbsdec(const unsigned char *string1,
 
229
                              const unsigned char *string2)
 
230
{
 
231
    // needs work dft
 
232
    return NULL;
 
233
}
 
234
 
 
235
static unsigned char *_mbsinc(const unsigned char *inCurrent)
 
236
{
 
237
    // needs work dft
 
238
    return (unsigned char *)(inCurrent + 1);
 
239
}
 
240
 
 
241
#endif
52
242
 
53
243
struct _MDLock               _pr_ioq_lock;
54
244
 
70
260
    FILE_GENERIC_EXECUTE
71
261
};
72
262
 
73
 
/*
74
 
 * The NSPR epoch (00:00:00 1 Jan 1970 UTC) in FILETIME.
75
 
 * We store the value in a PRTime variable for convenience.
76
 
 * This constant is used by _PR_FileTimeToPRTime().
77
 
 */
78
 
#if defined(__MINGW32__)
79
 
static const PRTime _pr_filetime_offset = 116444736000000000LL;
80
 
#else
81
 
static const PRTime _pr_filetime_offset = 116444736000000000i64;
82
 
#endif
83
 
 
 
263
/* Windows CE has GetFileAttributesEx. */
 
264
#ifndef WINCE
84
265
typedef BOOL (WINAPI *GetFileAttributesExFn)(LPCTSTR,
85
266
                                             GET_FILEEX_INFO_LEVELS,
86
267
                                             LPVOID); 
87
268
static GetFileAttributesExFn getFileAttributesEx;
88
269
static void InitGetFileInfo(void);
 
270
#endif
89
271
 
90
272
static void InitUnicodeSupport(void);
91
273
 
128
310
 
129
311
    _PR_NT_InitSids();
130
312
 
 
313
#ifndef WINCE
131
314
    InitGetFileInfo();
 
315
#endif
132
316
 
133
317
    InitUnicodeSupport();
134
318
 
227
411
            flags = OPEN_EXISTING;
228
412
    }
229
413
 
230
 
    file = CreateFile(name,
231
 
                      access,
232
 
                      FILE_SHARE_READ|FILE_SHARE_WRITE,
233
 
                      NULL,
234
 
                      flags,
235
 
                      flag6,
236
 
                      NULL);
 
414
    file = CreateFileA(name,
 
415
                       access,
 
416
                       FILE_SHARE_READ|FILE_SHARE_WRITE,
 
417
                       NULL,
 
418
                       flags,
 
419
                       flag6,
 
420
                       NULL);
237
421
    if (file == INVALID_HANDLE_VALUE) {
238
422
                _PR_MD_MAP_OPEN_ERROR(GetLastError());
239
423
        return -1; 
285
469
            flags = OPEN_EXISTING;
286
470
    }
287
471
 
288
 
    file = CreateFile(name,
289
 
                      access,
290
 
                      FILE_SHARE_READ|FILE_SHARE_WRITE,
291
 
                      lpSA,
292
 
                      flags,
293
 
                      flag6,
294
 
                      NULL);
 
472
    file = CreateFileA(name,
 
473
                       access,
 
474
                       FILE_SHARE_READ|FILE_SHARE_WRITE,
 
475
                       lpSA,
 
476
                       flags,
 
477
                       flag6,
 
478
                       NULL);
295
479
    if (lpSA != NULL) {
296
480
        _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
297
481
    }
471
655
#define GetFileFromDIR(d)       (d)->d_entry.cFileName
472
656
#define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
473
657
 
474
 
void FlipSlashes(char *cp, size_t len)
 
658
static void FlipSlashes(char *cp, size_t len)
475
659
{
476
660
    while (len-- > 0) {
477
661
        if (cp[0] == '/') {
530
714
    strcpy(&filename[len], "\\*.*");
531
715
    FlipSlashes( filename, strlen(filename) );
532
716
 
533
 
    d->d_hdl = FindFirstFile( filename, &(d->d_entry) );
 
717
    d->d_hdl = FindFirstFileA( filename, &(d->d_entry) );
534
718
    if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
535
719
                _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
536
720
        return PR_FAILURE;
553
737
                d->firstEntry = PR_FALSE;
554
738
                rv = 1;
555
739
            } else {
556
 
                rv = FindNextFile(d->d_hdl, &(d->d_entry));
 
740
                rv = FindNextFileA(d->d_hdl, &(d->d_entry));
557
741
            }
558
742
            if (rv == 0) {
559
743
                break;
582
766
PRInt32
583
767
_PR_MD_DELETE(const char *name)
584
768
{
585
 
    if (DeleteFile(name)) {
 
769
    if (DeleteFileA(name)) {
586
770
        return 0;
587
771
    } else {
588
772
                _PR_MD_MAP_DELETE_ERROR(GetLastError());
644
828
PRInt32
645
829
_PR_MD_STAT(const char *fn, struct stat *info)
646
830
{
 
831
#ifdef WINCE
 
832
    // needs work. dft
 
833
    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
 
834
    return -1;
 
835
#else
647
836
    PRInt32 rv;
648
837
 
649
838
    rv = _stat(fn, (struct _stat *)info);
675
864
        _PR_MD_MAP_STAT_ERROR(errno);
676
865
    }
677
866
    return rv;
 
867
#endif
678
868
}
679
869
 
680
870
#define _PR_IS_SLASH(ch) ((ch) == '/' || (ch) == '\\')
778
968
    return rv;
779
969
}
780
970
 
 
971
#ifndef WINCE
781
972
/*
782
973
 * InitGetFileInfo --
783
974
 *
878
1069
    FindClose(hFindFile);
879
1070
    return TRUE;
880
1071
}
 
1072
#endif
881
1073
 
882
1074
PRInt32
883
1075
_PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
884
1076
{
 
1077
#ifdef WINCE
 
1078
    WIN32_FILE_ATTRIBUTE_DATA findFileData;
 
1079
#else
885
1080
    WIN32_FIND_DATA findFileData;
 
1081
#endif
886
1082
    BOOL rv;
887
1083
    
888
1084
    if (NULL == fn || '\0' == *fn) {
890
1086
        return -1;
891
1087
    }
892
1088
 
 
1089
#ifdef WINCE
 
1090
    rv = GetFileAttributesExA(fn, GetFileExInfoStandard, &findFileData);
 
1091
#else
893
1092
    /* GetFileAttributesEx is supported on Win 2K and up. */
894
1093
    if (getFileAttributesEx) {
895
1094
        rv = getFileAttributesEx(fn, GetFileExInfoStandard, &findFileData);
896
1095
    } else {
897
1096
        rv = GetFileAttributesExFB(fn, &findFileData);
898
1097
    }
 
1098
#endif
899
1099
    if (!rv) {
900
1100
        _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
901
1101
        return -1;
983
1183
PRStatus
984
1184
_PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
985
1185
{
 
1186
#ifdef WINCE
 
1187
    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
 
1188
    return PR_FAILURE;
 
1189
#else
986
1190
    BOOL rv;
987
1191
 
988
1192
    /*
998
1202
        return PR_FAILURE;
999
1203
    }
1000
1204
    return PR_SUCCESS;
 
1205
#endif
1001
1206
1002
1207
 
1003
1208
void
1013
1218
void
1014
1219
_PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd)
1015
1220
{
 
1221
#ifdef WINCE
 
1222
    fd->secret->inheritable = _PR_TRI_FALSE;
 
1223
#else
1016
1224
    DWORD flags;
1017
1225
 
1018
1226
    PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
1023
1231
            fd->secret->inheritable = _PR_TRI_FALSE;
1024
1232
        }
1025
1233
    }
 
1234
#endif
1026
1235
}
1027
1236
 
1028
1237
PRInt32
1029
1238
_PR_MD_RENAME(const char *from, const char *to)
1030
1239
{
1031
1240
    /* Does this work with dot-relative pathnames? */
1032
 
    if (MoveFile(from, to)) {
 
1241
    if (MoveFileA(from, to)) {
1033
1242
        return 0;
1034
1243
    } else {
1035
1244
                _PR_MD_MAP_RENAME_ERROR(GetLastError());
1040
1249
PRInt32
1041
1250
_PR_MD_ACCESS(const char *name, PRAccessHow how)
1042
1251
{
 
1252
#ifdef WINCE
 
1253
    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
 
1254
    return -1;
 
1255
#else
1043
1256
PRInt32 rv;
1044
1257
    switch (how) {
1045
1258
      case PR_ACCESS_WRITE_OK:
1058
1271
        if (rv < 0)
1059
1272
                _PR_MD_MAP_ACCESS_ERROR(errno);
1060
1273
    return rv;
 
1274
#endif
1061
1275
}
1062
1276
 
1063
1277
PRInt32
1064
1278
_PR_MD_MKDIR(const char *name, PRIntn mode)
1065
1279
{
1066
1280
    /* XXXMB - how to translate the "mode"??? */
1067
 
    if (CreateDirectory(name, NULL)) {
 
1281
    if (CreateDirectoryA(name, NULL)) {
1068
1282
        return 0;
1069
1283
    } else {
1070
1284
                _PR_MD_MAP_MKDIR_ERROR(GetLastError());
1088
1302
        sa.bInheritHandle = FALSE;
1089
1303
        lpSA = &sa;
1090
1304
    }
1091
 
    rv = CreateDirectory(name, lpSA);
 
1305
    rv = CreateDirectoryA(name, lpSA);
1092
1306
    if (lpSA != NULL) {
1093
1307
        _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
1094
1308
    }
1103
1317
PRInt32
1104
1318
_PR_MD_RMDIR(const char *name)
1105
1319
{
1106
 
    if (RemoveDirectory(name)) {
 
1320
    if (RemoveDirectoryA(name)) {
1107
1321
        return 0;
1108
1322
    } else {
1109
1323
                _PR_MD_MAP_RMDIR_ERROR(GetLastError());
1187
1401
 
1188
1402
static void InitUnicodeSupport(void)
1189
1403
{
 
1404
#ifdef WINCE
 
1405
    /* The A functions don't even exist in Windows Mobile. */
 
1406
    _pr_useUnicode = PR_TRUE;
 
1407
#else
1190
1408
    /*
1191
1409
     * The W functions exist on Win9x as stubs that fail with the
1192
1410
     * ERROR_CALL_NOT_IMPLEMENTED error.  We plan to emulate the
1210
1428
    if (getenv("WINAPI_USE_ANSI"))
1211
1429
        _pr_useUnicode = PR_FALSE;
1212
1430
#endif
 
1431
#endif
1213
1432
}
1214
1433
 
1215
1434
#ifdef MOZ_UNICODE
1216
1435
 
1217
1436
/* ================ UTF16 Interfaces ================================ */
1218
 
void FlipSlashesW(PRUnichar *cp, size_t len)
 
1437
static void FlipSlashesW(PRUnichar *cp, size_t len)
1219
1438
{
1220
1439
    while (len-- > 0) {
1221
1440
        if (cp[0] == L'/') {