From: Phil W. <ph...@su...> - 2002-12-11 19:27:52
|
Hi Bruce, > > > vendorattribute.option = strdup(optarg); > > > is cleaner than: > > > vendorattribute.option = (char *)malloc(strlen(optarg)+1); > > > > Well, it looks nicer, but I don't really like the idea of making a copy of a > > string just to overwrite it. I know, I'm being silly :-) > > In fact this is *exactly* why I started thinking about it. My first > thought was "we don't need a copy!". But then I couldn't see a clean way > of doing it... until I thought of just eliminating the sscanf(). I used sscanf() so that a user could do this: $ smartctl -v 009,minutes -a /dev/hda or even this: $ smartctl -v ' 9 , minutes ' -a /dev/hda and it would still work. Though it doesn't seem to work if there is a space between the number and the comma. Phil |