#include <stdio.h>
#include <sys/types.h>
#include <string.h>
int trim_dots(const char * path
)
{
char * pos
= NULL;
pos
= strrchr(path
, '/');
printf("%s\n", pos
);
if(pos
== NULL)
{
perror("strrchr");
return -1;
}
if((strcmp(pos
+1, ".") == 0) || (strcmp(pos
+1, "..") == 0))
return 0;
else
return -2;
return 0;
}
int main(int argc
, const char *argv
[])
{
int ret
= -1;
const char * path1
= "12340/.";
const char * path2
= "abcd/..";
ret
= trim_dots(path1
);
if(ret
!= 0)
{
fprintf(stderr, "trim_dots error %d\n", ret
);
}
else
{
fprintf(stdout, "trim_dot ok!\n");
}
ret
= trim_dots(path2
);
if(ret
!= 0)
{
fprintf(stderr, "trim_dots error %d\n", ret
);
}
else
{
fprintf(stdout, "trim_dots ok!\n");
}
return 0;
}
测试结果
转载请注明原文地址:https://tech.qufami.com/read-9332.html