shithub: npe

ref: 4fa9b9a395c8ea38e83d84e0d483fe3a329958ea
dir: /libnpe/realpath.c/

View raw version
#include <u.h>
#include <libc.h>
#include "limits.h"

char *
realpath(char *path, char *buffer)
{
	char *s, p[PATH_MAX];
	int f;

	s = nil;
	if((f = open(path, OREAD)) < 0){
		if(fd2path(f, p, sizeof(p)) == 0)
			s = buffer == nil ? strdup(p) : strcpy(buffer, p);
		close(f);
	}

	return s;
}