代码拉取完成,页面将自动刷新
// Copyright 2014 Rui Ueyama. Released under the MIT license.
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include "8cc.h"
// Returns the shortest path for the given full path to a file.
static char *clean(char *p) {
assert(*p == '/');
char buf[PATH_MAX];
char *q = buf;
*q++ = '/';
for (;;) {
if (*p == '/') {
p++;
continue;
}
if (!memcmp("./", p, 2)) {
p += 2;
continue;
}
if (!memcmp("../", p, 3)) {
p += 3;
if (q == buf + 1)
continue;
for (q--; q[-1] != '/'; q--);
continue;
}
while (*p != '/' && *p != '\0')
*q++ = *p++;
if (*p == '/') {
*q++ = *p++;
continue;
}
*q = '\0';
return strdup(buf);
}
}
// Returns the shortest absolute path for the given path.
char *fullpath(char *path) {
static char cwd[PATH_MAX];
if (path[0] == '/')
return clean(path);
if (*cwd == '\0' && !getcwd(cwd, PATH_MAX))
error("getcwd failed: %s", strerror(errno));
return clean(format("%s/%s", cwd, path));
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。