ref: 3aef5b01a473555c92bba327ede73960daec22a8
dir: /libnpe/realpath.c/
#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); } if(s == nil && strlen(path) < sizeof(p)){ strcpy(buffer, path); s = cleanname(buffer); } return s; }