Пример #1
0
int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath)
{
	int rc;

	if(olddirfd != newdirfd) {
		fprintf(stderr, "tup compat renameat error: olddirfd=%i but newdirfd=%i\n", olddirfd, newdirfd);
		return -1;
	}

	dir_mutex_lock(olddirfd);
#ifdef _WIN32
	wchar_t woldpath[PATH_MAX];
	wchar_t wnewpath[PATH_MAX];
	MultiByteToWideChar(CP_UTF8, 0, oldpath, -1, woldpath, PATH_MAX);
	MultiByteToWideChar(CP_UTF8, 0, newpath, -1, wnewpath, PATH_MAX);

	if(MoveFileEx(woldpath, wnewpath, MOVEFILE_REPLACE_EXISTING)) {
		rc = 0;
	} else {
		rc = -1;
	}
#else
	rc = rename(oldpath, newpath);
#endif
	dir_mutex_unlock();
	return rc;
}
Пример #2
0
Файл: tmpfile.c Проект: 5kg/tup
FILE *__wrap_tmpfile(void)
{
	static int num = 0;
	int fd;
	char filename[64];
	FILE *f = NULL;
	HANDLE h;

	dir_mutex_lock(tup_top_fd());

	snprintf(filename, sizeof(filename), ".tup/tmp/tmpfile-%i", num);
	filename[sizeof(filename)-1] = 0;
	num++;

	/* Need to use CreateFile to be able to set it delete-on-close */
	h = CreateFile(filename, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
	if(h == INVALID_HANDLE_VALUE)
		goto err_out;

	/* Convert from HANDLE to FILE* */
	fd = _open_osfhandle((intptr_t)h, 0);
	if(fd < 0)
		goto err_out;
	f = fdopen(fd, "w+");
	if(!f) {
		if(!close(fd)) {
			perror("close(fd) in tmpfile()");
			goto err_out;
		}
	}
err_out:
	dir_mutex_unlock();

	return f;
}
Пример #3
0
int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
{
	int rc;

	dir_mutex_lock(dirfd);
	rc = readlink(pathname, buf, bufsiz);
	dir_mutex_unlock();
	return rc;
}
Пример #4
0
int symlinkat(const char *oldpath, int newdirfd, const char *newpath)
{
	int rc;

	dir_mutex_lock(newdirfd);
	rc = symlink(oldpath, newpath);
	dir_mutex_unlock();
	return rc;
}
Пример #5
0
int mkdirat(int dirfd, const char *pathname, mode_t mode)
{
	int rc;

	if(mode) {/* for win32 */}

	dir_mutex_lock(dirfd);
	rc = mkdir(pathname, mode);
	dir_mutex_unlock();
	return rc;
}
Пример #6
0
int faccessat(int dirfd, const char *pathname, int mode, int flags)
{
	int rc;

	if(flags) {/* No way to access() a symlink? */}

	dir_mutex_lock(dirfd);
	rc = access(pathname, mode);
	dir_mutex_unlock();
	return rc;
}
Пример #7
0
int unlinkat(int dirfd, const char *pathname, int flags)
{
	int rc;

	dir_mutex_lock(dirfd);
	if(flags == AT_REMOVEDIR)
		rc = rmdir(pathname);
	else
		rc = unlink(pathname);
	dir_mutex_unlock();
	return rc;
}
Пример #8
0
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags)
{
	int rc;

	dir_mutex_lock(dirfd);
	if(flags & AT_SYMLINK_NOFOLLOW) {
		rc = lstat(pathname, buf);
	} else {
		rc = stat(pathname, buf);
	}
	dir_mutex_unlock();
	return rc;
}
Пример #9
0
int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags)
{
	int rc;

	dir_mutex_lock(dirfd);
	if(flags & AT_SYMLINK_NOFOLLOW) {
		fprintf(stderr, "tup error: fchmodat(AT_SYMLINK_NOFOLLOW) not supported in compat library.\n");
		rc = -1;
		errno = ENOSYS;
	} else {
		rc = chmod(pathname, mode);
	}
	dir_mutex_unlock();
	return rc;
}
Пример #10
0
int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags)
{
	int rc;
	struct timeval tv[2];
	tv[0].tv_sec = times[0].tv_sec;
	tv[0].tv_usec = times[0].tv_nsec / 1000;
	tv[1].tv_sec = times[1].tv_sec;
	tv[1].tv_usec = times[1].tv_nsec / 1000;

	dir_mutex_lock(dirfd);
	if(flags & AT_SYMLINK_NOFOLLOW) {
		rc = lutimes(pathname, tv);
	} else {
		rc = utimes(pathname, tv);
	}
	dir_mutex_unlock();
	return rc;
}
Пример #11
0
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags)
{
	int rc;

	dir_mutex_lock(dirfd);
	if(flags & AT_SYMLINK_NOFOLLOW) {
#ifdef _WIN32
		open_notify(ACCESS_READ, pathname);
#endif
		rc = lstat(pathname, buf);
	} else {
#ifdef _WIN32
		open_notify(ACCESS_READ, pathname);
#endif
		rc = stat(pathname, buf);
	}
	dir_mutex_unlock();
	return rc;
}
Пример #12
0
Файл: renameat.c Проект: 5kg/tup
int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath)
{
	int rc;

	if(olddirfd != newdirfd) {
		fprintf(stderr, "tup compat renameat error: olddirfd=%i but newdirfd=%i\n", olddirfd, newdirfd);
		return -1;
	}

	dir_mutex_lock(olddirfd);
#ifdef _WIN32
	if(MoveFileEx(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) {
		rc = 0;
	} else {
		rc = -1;
	}
#else
	rc = rename(oldpath, newpath);
#endif
	dir_mutex_unlock();
	return rc;
}