aboutsummaryrefslogtreecommitdiff
path: root/lib/compat/src/chdir.c
blob: 17d814f1432b97d3396a99a4b54cde969d09db6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * chdir.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "config.h"
#include "compat.h"

#ifdef _WIN32
#include <stdlib.h>
#include <stdio.h>

int chdir(const char *path)
{
	WCHAR *wpath;
	int ret;

	wpath = path_to_windows(path);
	if (wpath == NULL)
		return -1;

	if (!SetCurrentDirectoryW(wpath)) {
		w32_perror(path);
		ret = -1;
	} else {
		ret = 0;
	}

	free(wpath);
	return ret;
}
#endif