Blame src/misc/nt64/realpath.c

716654
/**************************************************************************/
716654
/*  mmglue: midipix architecture- and target-specific bits for musl libc  */
716654
/*  Copyright (C) 2013--2023  SysDeer Technologies, LLC                   */
716654
/*  Released under the Standard MIT License; see COPYING.MMGLUE.          */
716654
/**************************************************************************/
716654
18b707
#include <limits.h>
18b707
#include <unistd.h>
18b707
#include <fcntl.h>
18b707
#include <string.h>
18b707
#include <errno.h>
2a80f1
#include "syscall.h"
18b707
18b707
extern const struct __psx_vtbl *  __psx_vtbl;
18b707
18b707
char * realpath(const char * restrict filename, char * restrict resolved)
18b707
{
18b707
	int  ecode;
18b707
	char buf[PATH_MAX];
18b707
18b707
	ecode = filename
2a80f1
		? __syscall(SYS_fs_rpath,
18b707
			AT_FDCWD,filename,
18b707
			O_NONBLOCK|O_CLOEXEC,
18b707
			buf,sizeof(buf))
18b707
		: -EINVAL;
18b707
18b707
	if (ecode < 0) {
18b707
		errno = -ecode;
18b707
		return 0;
18b707
	}
18b707
18b707
	return resolved
18b707
		? strcpy(resolved,buf)
18b707
		: strdup(buf);
18b707
}