From 92f4313665bc726baf055f81e2daae48c77123fc Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 5 Nov 2008 21:49:52 +0100 Subject: unify string replacement --- extras/ata_id/ata_id.c | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'extras/ata_id/ata_id.c') diff --git a/extras/ata_id/ata_id.c b/extras/ata_id/ata_id.c index a4f73b8dfd..d407b0fad9 100644 --- a/extras/ata_id/ata_id.c +++ b/extras/ata_id/ata_id.c @@ -44,38 +44,6 @@ static void log_fn(struct udev *udev, int priority, vsyslog(priority, format, args); } -static void set_str(char *to, const char *from, size_t count) -{ - size_t i, j, len; - - /* strip trailing whitespace */ - len = strnlen(from, count); - while (len && isspace(from[len-1])) - len--; - - /* strip leading whitespace */ - i = 0; - while (isspace(from[i]) && (i < len)) - i++; - - j = 0; - while (i < len) { - /* substitute multiple whitespace */ - if (isspace(from[i])) { - while (isspace(from[i])) - i++; - to[j++] = '_'; - } - /* skip chars */ - if (from[i] == '/') { - i++; - continue; - } - to[j++] = from[i++]; - } - to[j] = '\0'; -} - int main(int argc, char *argv[]) { struct udev *udev; @@ -146,9 +114,9 @@ int main(int argc, char *argv[]) goto close; } - set_str(model, (char *) id.model, 40); - set_str(serial, (char *) id.serial_no, 20); - set_str(revision, (char *) id.fw_rev, 8); + udev_util_replace_whitespace((char *) id.model, model, 40); + udev_util_replace_whitespace((char *) id.serial_no, serial, 20); + udev_util_replace_whitespace((char *) id.fw_rev, revision, 8); if (export) { if ((id.config >> 8) & 0x80) { -- cgit v1.2.3-54-g00ecf