Esempio n. 1
0
int S_windows_chmod(const char *pathname, int mode) {
  wchar_t wpathname[PATH_MAX];
  if (MultiByteToWideChar(CP_UTF8,0,pathname,-1,wpathname,PATH_MAX) == 0)
    return _chmod(pathname, mode);
  else
    return _wchmod(wpathname, mode);
}
Esempio n. 2
0
int p_unlink(const char *path)
{
	wchar_t buf[GIT_WIN_PATH];
	git__utf8_to_16(buf, GIT_WIN_PATH, path);
	_wchmod(buf, 0666);
	return _wunlink(buf);
}
Esempio n. 3
0
// BCC 5.5 and 5.5.1 have a bug in _wopen where files are created read only
// regardless of the mode parameter. This hack works around the problem by
// setting the mode with _wchmod.
//
int wxCRT_OpenW(const wchar_t *pathname, int flags, mode_t mode)
{
    int moreflags = 0;

    // we only want to fix the mode when the file is actually created, so
    // when creating first try doing it O_EXCL so we can tell if the file
    // was already there.
    if ((flags & O_CREAT) && !(flags & O_EXCL) && (mode & wxS_IWUSR) != 0)
        moreflags = O_EXCL;

    int fd = _wopen(pathname, flags | moreflags, mode);

    // the file was actually created and needs fixing
    if (fd != -1 && (flags & O_CREAT) != 0 && (mode & wxS_IWUSR) != 0)
    {
        close(fd);
        _wchmod(pathname, mode);
        fd = _wopen(pathname, flags & ~(O_EXCL | O_CREAT));
    }
    // the open failed, but it may have been because the added O_EXCL stopped
    // the opening of an existing file, so try again without.
    else if (fd == -1 && moreflags != 0)
    {
        fd = _wopen(pathname, flags & ~O_CREAT);
    }

    return fd;
}
Esempio n. 4
0
/**
 * g_chmod:
 * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
 * @mode: as in chmod()
 *
 * A wrapper for the POSIX chmod() function. The chmod() function is
 * used to set the permissions of a file system object.
 *
 * On Windows the file protection mechanism is not at all POSIX-like,
 * and the underlying chmod() function in the C library just sets or
 * clears the FAT-style READONLY attribute. It does not touch any
 * ACL. Software that needs to manage file permissions on Windows
 * exactly should use the Win32 API.
 *
 * See your C library manual for more details about chmod().
 *
 * Returns: zero if the operation succeeded, -1 on error.
 *
 * Since: 2.8
 */
int
g_chmod (const gchar *filename,
         int          mode)
{
#ifdef G_OS_WIN32
    wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
    int retval;
    int save_errno;

    if (wfilename == NULL)
    {
        errno = EINVAL;
        return -1;
    }

    retval = _wchmod (wfilename, mode);
    save_errno = errno;

    g_free (wfilename);

    errno = save_errno;
    return retval;
#else
    return chmod (filename, mode);
#endif
}
Esempio n. 5
0
int p_unlink(const char *path)
{
	git_win32_path buf;
	git_win32_path_from_c(buf, path);
	_wchmod(buf, 0666);
	return _wunlink(buf);
}
Esempio n. 6
0
/*
 * Change permission mode on file `path'.
 */
void eif_file_chmod(EIF_FILENAME path, int mode) {
	errno = 0;
#ifdef EIF_WINDOWS
	if (_wchmod(path, mode) == -1) {
#else
	if (chmod(path, mode) == -1) {
#endif
		esys();
	}
}

/*
 * Change the owner of the file to `uid'.
 */
void eif_file_chown(EIF_FILENAME name, int uid) {
#ifdef HAS_CHOWN
	int gid;
	rt_stat_buf buf;

	rt_file_stat(name, &buf);
	gid = buf.st_gid;
	errno = 0;
	if (chown(name, uid, gid) == -1) {
		esys();
	}
#endif
}
Esempio n. 7
0
int p_chmod(const char* path, mode_t mode)
{
	wchar_t* buf = gitwin_to_utf16(path);
	int ret = _wchmod(buf, mode);

	git__free(buf);
	return ret;
}
Esempio n. 8
0
int my_wchmod(const wchar_t * path, int mode)
{
#ifdef _WIN32
	return _wchmod(path, mode);
#else
	return chmod(wideCharToUtf8(path).c_str(), mode);
#endif
}
int
hssystemfileio_copy_permissions(const wchar_t *old_path, const wchar_t *new_path)
{
	struct __stat64 st;
	int rc = _wstat64(old_path, &st);
	if (rc == -1)
	{ return rc; }
	
	return _wchmod(new_path, st.st_mode);
}
Esempio n. 10
0
BOOLEAN RemoveDirectoryPath(_In_ PWSTR DirPath)
{
    HANDLE findHandle;
    PPH_STRING findPath;
    WIN32_FIND_DATA data = { 0 };

    findPath = PhConcatStrings2(DirPath, L"\\*");

    if ((findHandle = FindFirstFile(findPath->Buffer, &data)) == INVALID_HANDLE_VALUE)
    {
        if (GetLastError() == ERROR_FILE_NOT_FOUND)
        {
            PhDereferenceObject(findPath);
            return TRUE;
        }

        PhDereferenceObject(findPath);
        return FALSE;
    }

    do
    {
        if (PhEqualStringZ(data.cFileName, L".", TRUE) || PhEqualStringZ(data.cFileName, L"..", TRUE))
            continue;

        if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            PPH_STRING dirPath = PhConcatStrings(3, DirPath, L"\\", data.cFileName);

            RemoveDirectoryPath(dirPath->Buffer);
            PhDereferenceObject(dirPath);
        }
        else
        {
            PPH_STRING filePath = PhConcatStrings(3, DirPath, L"\\", data.cFileName);

            if (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
            {
                _wchmod(filePath->Buffer, _S_IWRITE);
            }

            SetupDeleteDirectoryFile(filePath->Buffer);
            PhDereferenceObject(filePath);
        }

    } while (FindNextFile(findHandle, &data));

    FindClose(findHandle);

    // Delete the parent directory
    RemoveDirectory(DirPath);

    PhDereferenceObject(findPath);
    return TRUE;
}
Esempio n. 11
0
int chmod_utf8(const char *filename, int pmode)
{
	wchar_t *wname;
	int ret;

	if (!(wname = wchar_from_utf8(filename))) return -1;
	ret = _wchmod(wname, pmode);
	free(wname);

	return ret;
}
Esempio n. 12
0
bool plFileSystem::Unlink(const plFileName &filename)
{
#if HS_BUILD_FOR_WIN32
    plStringBuffer<wchar_t> wfilename = filename.AsString().ToWchar();
    _wchmod(wfilename, S_IWRITE);
    return _wunlink(wfilename) == 0;
#else
    chmod(filename.AsString().c_str(), S_IWRITE);
    return unlink(filename.AsString().c_str()) == 0;
#endif
}
Esempio n. 13
0
/*
 * os_chmod -- chmod abstraction layer
 */
int
os_chmod(const char *pathname, mode_t mode)
{
	wchar_t *path = util_toUTF16(pathname);
	if (path == NULL)
		return -1;

	int ret = _wchmod(path, mode);
	util_free_UTF16(path);
	return ret;
}
Esempio n. 14
0
int p_unlink(const char *path)
{
	int ret = 0;
	wchar_t* buf;

	buf = gitwin_to_utf16(path);
	_wchmod(buf, 0666);
	ret = _wunlink(buf);
	git__free(buf);

	return ret;
}
Esempio n. 15
0
bool plFileUtils::RemoveFile(const wchar_t* filename, bool delReadOnly)
{
#ifdef HS_BUILD_FOR_WIN32
    if (delReadOnly)
        _wchmod(filename, S_IWRITE);
    return (_wunlink(filename) == 0);
#elif HS_BUILD_FOR_UNIX
    const char* cfilename = hsWStringToString(filename);
    bool ret = RemoveFile(cfilename, delReadOnly);
    delete[] cfilename; /* Free the string */

    return ret;
#endif
}
int win_fchmod(int fildes, mode_t mode)
{
    wchar_t *winpath;
    int ret;

    winpath = intpath2winpath(get_fdname(fildes));
    if (!winpath) {
	errno = EINVAL;
	return -1;
    }

    ret = _wchmod(winpath, mode);
    free(winpath);
    return ret;
}
Esempio n. 17
0
int flac_internal_chmod_utf8(const char *filename, int pmode)
{
	if (!utf8_filenames) {
		return _chmod(filename, pmode);
	} else {
		wchar_t *wname;
		int ret;

		if (!(wname = wchar_from_utf8(filename))) return -1;
		ret = _wchmod(wname, pmode);
		free(wname);

		return ret;
	}
}
int32 SetPosixPermissions(ExtensionString filename, int32 mode)
{
    DWORD dwAttr = GetFileAttributes(filename.c_str());

    if (dwAttr == INVALID_FILE_ATTRIBUTES)
        return ERR_NOT_FOUND;

    if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0)
        return NO_ERROR;

    bool write = (mode & 0200) != 0; 
    bool read = (mode & 0400) != 0;
    int mask = (write ? _S_IWRITE : 0) | (read ? _S_IREAD : 0);

    if (_wchmod(filename.c_str(), mask) == -1) {
        return ConvertErrnoCode(errno); 
    }

    return NO_ERROR;
}
int win_chmod(const char *path, mode_t mode)
{
    wchar_t *winpath;
    int ret;

    if (!strcmp("/", path)) {
	/* Emulate root */
	errno = EROFS;
	return -1;
    }

    winpath = intpath2winpath(path);
    if (!winpath) {
	errno = EINVAL;
	return -1;
    }

    ret = _wchmod(winpath, mode);
    free(winpath);
    return ret;
}
Esempio n. 20
0
/**
 * Sets the WRITABLE attribute for the specified file or directory
 *
 * @param pathName      name in UNICODE of file or directory
 * @param pathNameLen   length of path name
 * @param value         JAVACALL_TRUE to set file as writable
 *                      JAVACALL_FALSE to set file as not writable
 * @return <tt>JAVACALL_OK</tt> if operation completed successfully
 *         <tt>JAVACALL_FAIL</tt> if an error occured
 */ 
javacall_result javacall_fileconnection_set_writable(const javacall_utf16* pathName,
                                                     int pathNameLen,
                                                     javacall_bool value) {

    wchar_t wOsFilename[JAVACALL_MAX_FILE_NAME_LENGTH]; // max file name

    if( pathNameLen > JAVACALL_MAX_FILE_NAME_LENGTH ) {
        javacall_print("Error: javacall_fileconnection_set_writable(), file name is too long\n");
        return JAVACALL_FAIL;
    }

    memcpy(wOsFilename, pathName, pathNameLen*sizeof(wchar_t));
    wOsFilename[pathNameLen] = 0;

    if(_wchmod(wOsFilename, (JAVACALL_TRUE == value) ? _S_IWRITE : _S_IREAD) == -1) {
        javacall_print("Error: javacall_fileconnection_set_writable(), file is not accessible\n");
        return JAVACALL_FAIL;
    }

    return JAVACALL_OK;
}
Esempio n. 21
0
/**
 * Change the file-permission settings.
 */
int _win_chmod(const char *filename, int pmode)
{
  wchar_t szFile[_MAX_PATH + 1];
  long lRet;

  pmode &= (_S_IREAD | _S_IWRITE);

  if (_plibc_utf8_mode == 1)
    lRet = plibc_conv_to_win_pathwconv(filename, szFile, _MAX_PATH);
  else
    lRet = plibc_conv_to_win_path(filename, (char *) szFile, _MAX_PATH);
  if (lRet != ERROR_SUCCESS)
  {
    SetErrnoFromWinError(lRet);
    return -1;
  }

  /* chmod sets errno */
  if (_plibc_utf8_mode == 1)
    return _wchmod(szFile, pmode);
  else
    return chmod((char *) szFile, pmode);
}
Esempio n. 22
0
int VMPI_chmod16(const wchar *path, int mode)
{
    return _wchmod( path, (mode_t) mode );
}
Esempio n. 23
0
bool qt_wince__chmod(const char *file, int mode)
{
    return _wchmod( reinterpret_cast<const wchar_t *> (QString::fromLatin1(file).utf16()), mode);
}
Esempio n. 24
0
int chmod_( BBString *path,int mode ){
	if( _bbusew ) return _wchmod( bbTmpWString(path),mode );
	return _chmod( bbTmpCString(path),mode );
}