#include #include #include #include #include #include #define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char)) int determine(const char *a); void *nmalloc(size_t howmuch); int mistakes; int main(int argc, char** argv) { int m; char *filename = &argv[1][0]; m = determine(filename); if (m == 0) printf("New File"); else printf("Invalid path"); printf("\nExiting.\n"); return 0; } /* Determine whether the components in a path are valid directories. * Anything above zero means that it contains non-existent ones. */ int determine(const char *a) { int i, len = strlen(a); char *x; struct stat buf2; mistakes = 0; x = charalloc(len * sizeof(char)); for (i = len; i >= 0; --i) { if (a[i] == '/') { strncpy(x, a, i + 1); x[i + 2] = '\0'; if (stat(x, &buf2) == -1) ++mistakes; } } free(x); return mistakes; } void *nmalloc(size_t howmuch) { void *r = malloc(howmuch); if (r == NULL && howmuch != 0) printf("nmalloc error.\n");//die(_("nano is out of memory!")); return r; }