|
From: | Rishabh Dave |
Subject: | Re: [Nano-devel] Patch for bug #44950 |
Date: | Sun, 10 Jan 2016 12:21:22 +0530 |
On 10 Jan 2016 01:13, Rishabh Dave wrote:
> +/* Determine whether the components in a path are valid directories. If
> + * some component is faulty return it, else return NULL. */
> + char *fault_in_path(const char *filename)
> +{
> + int lenpath, lenparent, lenpparent;
> + lenpath= strlen(filename);
> + char *parentdir = charalloc(lenpath * sizeof(char));
> + char *pparentdir = charalloc(lenpath * sizeof(char));
> + /* pparentdir implies parent of parent directory */
> + char *fault;
> + struct stat parentinfo, pparentinfo;
> +
> + strcpy(parentdir, filename);
> + parentdir = dirname(parentdir);
> + strcpy(pparentdir, parentdir);
> + pparentdir = dirname(pparentdir);
doesn't nano have a strdup helper ? malloc+strcpy == strdup.
> + /* If path exists, and parent directory is a directory and not a regular or
> + * some other file, then New File can be established, so return NULL. */
> + if (stat(parentdir, &parentinfo) != -1 && S_ISDIR(parentinfo.st_mode))
> + return NULL;
this leaks memory
> +
> + do {
> + /* Check if parent's parent directory exists, if not keep checking further.
> + * If it does exist, extract faulty directory, turn faulty_path flag on and
> + * return faulty directory. */
> + if (stat(pparentdir, &pparentinfo) == -1 || !S_ISDIR(pparentinfo.st_mode)) {
> + strcpy(parentdir, pparentdir);
> + } else {
indentation is broken here
-mike
[Prev in Thread] | Current Thread | [Next in Thread] |