On 12/29/11 06:09, Jim Meyering wrote: > + /* If dev_name is a long-named symlink like > + /dev/disk/by-uuid/828fc648-9f30-43d8-a0b1-f7196a2edb66 and its > + canonical name is shorter, use the shorter name. But don't bother > + checking when DEV_NAME is no longer than e.g., "/dev/sda1" */ > + if (resolve_device_symlink && 9 < orig_len > + && (resolved_dev = canonicalize_filename_mode (dev_name, > CAN_EXISTING))) > + { > + if (strlen (resolved_dev) < orig_len) > + { > + free (dev_name); > + dev_name = resolved_dev; > + } > + else > + { > + free (resolved_dev); > + } > + }
I have some qualms about that "is shorter" part; couldn't that lead to confusing results, on systems where the canonical name is sometimes a bit shorter and sometimes a bit longer? Also, that "9 < orig_len" could also cause confusion. The flag "resolve_device_symlink" suggests that the name should always be resolved, at any rate. In short, how a simpler approach, that always resolves symlinks? Something like this: /* If dev_name is a symlink use the resolved name. On recent GNU/Linux systems we often see a symlink from, e.g., /dev/disk/by-uuid/828fc648-9f30-43d8-a0b1-f7196a2edb66 tp /dev/sda3 and it's better to output /dev/sda3. */ if (resolve_device_symlink && (resolved_dev = canonicalize_filename_mode (dev_name, CAN_EXISTING))) { free (dev_name); dev_name = resolved_dev; }