< prev index next >

src/java.base/share/native/libzip/zip_util.c

Print this page




 119         FILE_FLAG_WRITE_THROUGH :
 120         FILE_ATTRIBUTE_NORMAL;
 121     const DWORD maybeDeleteOnClose =
 122         (flags & O_TEMPORARY) ?
 123         FILE_FLAG_DELETE_ON_CLOSE :
 124         FILE_ATTRIBUTE_NORMAL;
 125     const DWORD flagsAndAttributes = maybeWriteThrough | maybeDeleteOnClose;
 126 
 127     fname_length = strlen(fname);
 128     if (fname_length < MAX_PATH) {
 129         return (jlong)CreateFile(
 130             fname,              /* path name in multibyte char */
 131             access,             /* Read and/or write permission */
 132             sharing,            /* File sharing flags */
 133             NULL,               /* Security attributes */
 134             disposition,        /* creation disposition */
 135             flagsAndAttributes, /* flags and attributes */
 136             NULL);
 137     } else {
 138         /* Get required buffer size to convert to Unicode */
 139         int wfname_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS,
 140                                              fname, -1, NULL, 0);
 141         if (wfname_len == 0) {
 142             return (jlong)INVALID_HANDLE_VALUE;
 143         }
 144         if ((wfname = (WCHAR*)malloc(wfname_len * sizeof(WCHAR))) == NULL) {
 145             return (jlong)INVALID_HANDLE_VALUE;
 146         }
 147         if (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS,
 148                                 fname, -1, wfname, wfname_len) == 0) {
 149             free(wfname);
 150             return (jlong)INVALID_HANDLE_VALUE;
 151         }
 152         wprefixed_fname = getPrefixed(wfname, (int)fname_length);
 153         fhandle = (jlong)CreateFileW(
 154             wprefixed_fname,    /* Wide char path name */
 155             access,             /* Read and/or write permission */
 156             sharing,            /* File sharing flags */
 157             NULL,               /* Security attributes */
 158             disposition,        /* creation disposition */
 159             flagsAndAttributes, /* flags and attributes */
 160             NULL);
 161         free(wfname);
 162         free(wprefixed_fname);
 163         return fhandle;
 164     }
 165 #else
 166     return open(fname, flags, 0);
 167 #endif




 119         FILE_FLAG_WRITE_THROUGH :
 120         FILE_ATTRIBUTE_NORMAL;
 121     const DWORD maybeDeleteOnClose =
 122         (flags & O_TEMPORARY) ?
 123         FILE_FLAG_DELETE_ON_CLOSE :
 124         FILE_ATTRIBUTE_NORMAL;
 125     const DWORD flagsAndAttributes = maybeWriteThrough | maybeDeleteOnClose;
 126 
 127     fname_length = strlen(fname);
 128     if (fname_length < MAX_PATH) {
 129         return (jlong)CreateFile(
 130             fname,              /* path name in multibyte char */
 131             access,             /* Read and/or write permission */
 132             sharing,            /* File sharing flags */
 133             NULL,               /* Security attributes */
 134             disposition,        /* creation disposition */
 135             flagsAndAttributes, /* flags and attributes */
 136             NULL);
 137     } else {
 138         /* Get required buffer size to convert to Unicode */
 139         int wfname_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
 140                                              fname, -1, NULL, 0);
 141         if (wfname_len == 0) {
 142             return (jlong)INVALID_HANDLE_VALUE;
 143         }
 144         if ((wfname = (WCHAR*)malloc(wfname_len * sizeof(WCHAR))) == NULL) {
 145             return (jlong)INVALID_HANDLE_VALUE;
 146         }
 147         if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
 148                                 fname, -1, wfname, wfname_len) == 0) {
 149             free(wfname);
 150             return (jlong)INVALID_HANDLE_VALUE;
 151         }
 152         wprefixed_fname = getPrefixed(wfname, (int)fname_length);
 153         fhandle = (jlong)CreateFileW(
 154             wprefixed_fname,    /* Wide char path name */
 155             access,             /* Read and/or write permission */
 156             sharing,            /* File sharing flags */
 157             NULL,               /* Security attributes */
 158             disposition,        /* creation disposition */
 159             flagsAndAttributes, /* flags and attributes */
 160             NULL);
 161         free(wfname);
 162         free(wprefixed_fname);
 163         return fhandle;
 164     }
 165 #else
 166     return open(fname, flags, 0);
 167 #endif


< prev index next >