Felix Zielcke <[EMAIL PROTECTED]> writes: > Am Freitag, den 01.08.2008, 17:09 +0200 schrieb Felix Zielcke: > >> Maybe there's a way to make it even better so please comment all of you >> grub-devels :) > > Thanks to Robert who suggested asprintf > > I hope the #define _GNU_SOURCE which is needed for it isn't a problem, > you use anyway gcc specific extentions and GRUB is a GNU project :)
AFAIK it isn't, so better leave it away. > I hadn't yet an idea how to solve that md_dNNpNN case with it, so I just > moved the xmalloc() call down to that. What's the problem? > Please comment which way you mostly like. I would prefer a changelog entry while commenting. > Index: util/getroot.c > =================================================================== > --- util/getroot.c (Revision 1757) > +++ util/getroot.c (Arbeitskopie) > @@ -17,6 +17,7 @@ > * along with GRUB. If not, see <http://www.gnu.org/licenses/>. > */ > > +#define _GNU_SOURCE > #include <sys/stat.h> > #include <unistd.h> > #include <string.h> > @@ -407,17 +408,16 @@ > switch (grub_util_get_dev_abstraction (os_dev)) > { > case GRUB_DEV_ABSTRACTION_LVM: > - grub_dev = xmalloc (strlen (os_dev) - 12 + 1); > > - strcpy (grub_dev, os_dev + 12); > - > + asprintf(&grub_dev,"%s",os_dev + strlen("/dev/mapper/") -1); Please add a space between asprintf and (&grub_dev .... Same for the lines below. > break; > > case GRUB_DEV_ABSTRACTION_RAID: > - grub_dev = xmalloc (20); > > if (os_dev[7] == '_' && os_dev[8] == 'd') > { > + grub_dev = xmalloc (20); > + > const char *p; > > /* This a partitionable RAID device of the form /dev/md_dNNpMM. */ > @@ -457,9 +457,12 @@ > } > else if (os_dev[7] >= '0' && os_dev[7] <= '9') > { > - memcpy (grub_dev, os_dev + 5, 7); > - grub_dev[7] = '\0'; > + asprintf(&grub_dev,"md%s",os_dev + sizeof("/dev/md") -1); > } > + else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9') > + { > + asprintf(&grub_dev,"md%s",os_dev + sizeof("/dev/md/") -1); > + } > else > grub_util_error ("Unknown kind of RAID device `%s'", os_dev); > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel