[BusyBox] [PATCH] Add -b and -S flags to ln.c.
Vladimir N. Oleynik
dzo at simtreas.ru
Sun Apr 17 08:25:10 UTC 2005
Matthew,
> The following patch adds support for the -S and -b flags to `ln'.
> + int backup_len = strlen(src) + strlen(suffix) + 2;
1) only +1 require
> + char *backup = xmalloc(backup_len);
> + snprintf(backup, backup_len, "%s%s", src, suffix);
2) this 3 lines equivalent with one line:
bb_xasprintf(&backup, "%s%s", src, suffix);
> + if (rename(src, backup) < 0 && errno != ENOENT) {
> + bb_perror_msg(src);
> + status = EXIT_FAILURE;
> + break;
3) don`t know, but "break" may be non good idea
> + }
> + /*
> + * When the source and dest are both hard links, a rename
> + * may succeed even though nothing happened. Therefore,
> + * always unlink().
> + */
> + unlink(src);
4) have memory leak, should use free(backup);
--w
vodz
More information about the busybox
mailing list