On Sun, 23 Aug 2015 19:21:42 +1000
Steven McDonald <[email protected]> wrote:
> Also, section 6.9.1 clause 9 of C99[0] says that "each parameter has
> automatic storage duration", so I think it's not safe to rely on a
> function parameter still being a valid object outside of openpartition
> (please correct me if I'm wrong on that).
Sorry, I just realised that it's fine to use name because it's only the
value pointed to by name that is being used in my diff.
Index: tunefs.c
===================================================================
RCS file: /cvs/src/sbin/tunefs/tunefs.c,v
retrieving revision 1.37
diff -u -p -r1.37 tunefs.c
--- tunefs.c 7 Feb 2015 02:09:14 -0000 1.37
+++ tunefs.c 23 Aug 2015 09:43:48 -0000
@@ -309,21 +309,18 @@ bread(daddr_t blk, char *buffer, int cnt
static int
openpartition(char *name, int flags, char **devicep)
{
- char rawspec[PATH_MAX], *p;
+ char *p;
struct fstab *fs;
int fd;
fs = getfsfile(name);
if (fs) {
- if ((p = strrchr(fs->fs_spec, '/')) != NULL) {
- snprintf(rawspec, sizeof(rawspec), "%.*s/r%s",
- (int)(p - fs->fs_spec), fs->fs_spec, p + 1);
- name = rawspec;
- } else
- name = fs->fs_spec;
+ name = fs->fs_spec;
+ if ((p = strrchr(name, '/')) != NULL)
+ name = p + 1;
}
fd = opendev(name, flags, 0, devicep);
if (fd == -1 && errno == ENOENT)
- devicep = &name;
+ *devicep = name;
return (fd);
}