< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 99,109 **** */ static ZFILE ZFILE_Open(const char *fname, int flags) { #ifdef WIN32 WCHAR *wfname, *wprefixed_fname; ! size_t converted_chars, fname_length; jlong fhandle; const DWORD access = (flags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : (flags & O_WRONLY) ? GENERIC_WRITE : GENERIC_READ; --- 99,109 ---- */ static ZFILE ZFILE_Open(const char *fname, int flags) { #ifdef WIN32 WCHAR *wfname, *wprefixed_fname; ! size_t fname_length; jlong fhandle; const DWORD access = (flags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : (flags & O_WRONLY) ? GENERIC_WRITE : GENERIC_READ;
*** 133,149 **** NULL, /* Security attributes */ disposition, /* creation disposition */ flagsAndAttributes, /* flags and attributes */ NULL); } else { ! if ((wfname = (WCHAR*)malloc((fname_length + 1) * sizeof(WCHAR))) == NULL) return (jlong)INVALID_HANDLE_VALUE; ! ! if (mbstowcs_s(&converted_chars, wfname, fname_length + 1, fname, fname_length) != 0) { ! free(wfname); return (jlong)INVALID_HANDLE_VALUE; } wprefixed_fname = getPrefixed(wfname, (int)fname_length); fhandle = (jlong)CreateFileW( wprefixed_fname, /* Wide char path name */ access, /* Read and/or write permission */ sharing, /* File sharing flags */ --- 133,153 ---- NULL, /* Security attributes */ disposition, /* creation disposition */ flagsAndAttributes, /* flags and attributes */ NULL); } else { ! /* Get required buffer size to convert to Unicode */ ! int wfname_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, ! fname, -1, NULL, 0); ! if (wfname_len == 0) { return (jlong)INVALID_HANDLE_VALUE; ! } ! if ((wfname = (WCHAR*)malloc(wfname_len * sizeof(WCHAR))) == NULL) { return (jlong)INVALID_HANDLE_VALUE; } + MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, + fname, -1, wfname, wfname_len); wprefixed_fname = getPrefixed(wfname, (int)fname_length); fhandle = (jlong)CreateFileW( wprefixed_fname, /* Wide char path name */ access, /* Read and/or write permission */ sharing, /* File sharing flags */
< prev index next >