Move mkpath() higher up so we don't need to declare it

This commit is contained in:
sin 2016-02-10 15:38:22 +00:00
parent 5629b49113
commit afc0652067

41
noice.c
View file

@ -103,7 +103,6 @@ int idle;
void printmsg(char *); void printmsg(char *);
void printwarn(void); void printwarn(void);
void printerr(int, char *); void printerr(int, char *);
char *mkpath(char *, char *, char *, size_t);
#undef dprintf #undef dprintf
int int
@ -361,6 +360,26 @@ canopendir(char *path)
return 1; return 1;
} }
char *
mkpath(char *dir, char *name, char *out, size_t n)
{
/* Handle absolute path */
if (name[0] == '/') {
strlcpy(out, name, n);
} else {
/* Handle root case */
if (strcmp(dir, "/") == 0) {
strlcpy(out, "/", n);
strlcat(out, name, n);
} else {
strlcpy(out, dir, n);
strlcat(out, "/", n);
strlcat(out, name, n);
}
}
return out;
}
void void
printent(struct entry *ent, int active) printent(struct entry *ent, int active)
{ {
@ -444,26 +463,6 @@ dentfree(struct entry *dents)
free(dents); free(dents);
} }
char *
mkpath(char *dir, char *name, char *out, size_t n)
{
/* Handle absolute path */
if (name[0] == '/') {
strlcpy(out, name, n);
} else {
/* Handle root case */
if (strcmp(dir, "/") == 0) {
strlcpy(out, "/", n);
strlcat(out, name, n);
} else {
strlcpy(out, dir, n);
strlcat(out, "/", n);
strlcat(out, name, n);
}
}
return out;
}
/* Return the position of the matching entry or 0 otherwise */ /* Return the position of the matching entry or 0 otherwise */
int int
dentfind(struct entry *dents, int n, char *cwd, char *path) dentfind(struct entry *dents, int n, char *cwd, char *path)