diff options
Diffstat (limited to 'extras')
-rw-r--r-- | extras/ata_id/ata_id.c | 38 | ||||
-rw-r--r-- | extras/scsi_id/scsi_id.c | 47 | ||||
-rw-r--r-- | extras/usb_id/usb_id.c | 52 | ||||
-rw-r--r-- | extras/volume_id/vol_id.c | 40 |
4 files changed, 21 insertions, 156 deletions
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) { diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c index 45e48601f7..69994dd9d3 100644 --- a/extras/scsi_id/scsi_id.c +++ b/extras/scsi_id/scsi_id.c @@ -69,39 +69,7 @@ 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'; -} - -static void set_type(char *to, const char *from, size_t len) +static void set_type(const char *from, char *to, size_t len) { int type_num; char *eptr; @@ -533,11 +501,10 @@ static int set_inq_values(struct udev *udev, struct scsi_id_device *dev_scsi, co if (retval) return retval; - set_str(vendor_str, dev_scsi->vendor, sizeof(vendor_str)); - set_str(model_str, dev_scsi->model, sizeof(model_str)); - set_type(type_str, dev_scsi->type, sizeof(type_str)); - set_str(revision_str, dev_scsi->revision, sizeof(revision_str)); - + udev_util_replace_whitespace(dev_scsi->vendor, vendor_str, sizeof(vendor_str)); + udev_util_replace_whitespace(dev_scsi->model, model_str, sizeof(model_str)); + set_type(dev_scsi->type, type_str, sizeof(type_str)); + udev_util_replace_whitespace(dev_scsi->revision, revision_str, sizeof(revision_str)); return 0; } @@ -604,9 +571,9 @@ static int scsi_id(struct udev *udev, char *maj_min_dev) printf("ID_VENDOR=%s\n", vendor_str); printf("ID_MODEL=%s\n", model_str); printf("ID_REVISION=%s\n", revision_str); - set_str(serial_str, dev_scsi.serial, sizeof(serial_str)); + udev_util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str)); printf("ID_SERIAL=%s\n", serial_str); - set_str(serial_str, serial_short, sizeof(serial_str)); + udev_util_replace_whitespace(serial_short, serial_str, sizeof(serial_str)); printf("ID_SERIAL_SHORT=%s\n", serial_str); printf("ID_TYPE=%s\n", type_str); } else { diff --git a/extras/usb_id/usb_id.c b/extras/usb_id/usb_id.c index 1499695c67..6dd1d450fb 100644 --- a/extras/usb_id/usb_id.c +++ b/extras/usb_id/usb_id.c @@ -46,44 +46,6 @@ static char instance_str[64]; static int use_usb_info; static int use_num_info; -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++] = '_'; - } - /* Replace '/' with '.' */ - if (from[i] == '/') { - to[j++] = '.'; - i++; - continue; - } - /* skip non-printable chars */ - if (!isalnum(from[i]) && !ispunct(from[i])) { - i++; - continue; - } - to[j++] = from[i++]; - } - to[j] = '\0'; -} - static void set_usb_iftype(char *to, int if_class_num, size_t len) { char *type = "generic"; @@ -274,7 +236,7 @@ static int usb_id(struct udev_device *dev) udev_device_get_sysname(dev_scsi)); goto fallback; } - set_str(vendor_str, scsi_vendor, sizeof(vendor_str)-1); + udev_util_replace_whitespace(scsi_vendor, vendor_str, sizeof(vendor_str)-1); scsi_model = udev_device_get_sysattr_value(dev_scsi, "model"); if (!scsi_model) { @@ -282,7 +244,7 @@ static int usb_id(struct udev_device *dev) udev_device_get_sysname(dev_scsi)); goto fallback; } - set_str(model_str, scsi_model, sizeof(model_str)-1); + udev_util_replace_whitespace(scsi_model, model_str, sizeof(model_str)-1); scsi_type = udev_device_get_sysattr_value(dev_scsi, "type"); if (!scsi_type) { @@ -298,7 +260,7 @@ static int usb_id(struct udev_device *dev) udev_device_get_sysname(dev_scsi)); goto fallback; } - set_str(revision_str, scsi_rev, sizeof(revision_str)-1); + udev_util_replace_whitespace(scsi_rev, revision_str, sizeof(revision_str)-1); /* * some broken devices have the same identifiers @@ -322,7 +284,7 @@ fallback: info(udev, "No USB vendor information available\n"); return 1; } - set_str(vendor_str, usb_vendor, sizeof(vendor_str)-1); + udev_util_replace_whitespace(usb_vendor, vendor_str, sizeof(vendor_str)-1); } if (model_str[0] == '\0') { @@ -338,7 +300,7 @@ fallback: dbg(udev, "No USB model information available\n"); return 1; } - set_str(model_str, usb_model, sizeof(model_str)-1); + udev_util_replace_whitespace(usb_model, model_str, sizeof(model_str)-1); } if (revision_str[0] == '\0') { @@ -346,7 +308,7 @@ fallback: usb_rev = udev_device_get_sysattr_value(dev_usb, "bcdDevice"); if (usb_rev) - set_str(revision_str, usb_rev, sizeof(revision_str)-1); + udev_util_replace_whitespace(usb_rev, revision_str, sizeof(revision_str)-1); } if (serial_str[0] == '\0') { @@ -354,7 +316,7 @@ fallback: usb_serial = udev_device_get_sysattr_value(dev_usb, "serial"); if (usb_serial) - set_str(serial_str, usb_serial, sizeof(serial_str)-1); + udev_util_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1); } return 0; } diff --git a/extras/volume_id/vol_id.c b/extras/volume_id/vol_id.c index b4db5adcd8..df47501a6b 100644 --- a/extras/volume_id/vol_id.c +++ b/extras/volume_id/vol_id.c @@ -66,38 +66,6 @@ static void vid_log(int priority, const char *file, int line, const char *format return; } -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'; -} - static int all_probers(volume_id_probe_fn_t probe_fn, struct volume_id *id, uint64_t off, uint64_t size, void *data) @@ -288,12 +256,12 @@ int main(int argc, char *argv[]) goto exit; } - set_str(label_safe, label, sizeof(label_safe)); - util_replace_chars(label_safe, ALLOWED_CHARS_INPUT); + udev_util_replace_whitespace(label, label_safe, sizeof(label_safe)); + udev_util_replace_chars(label_safe, UDEV_ALLOWED_CHARS_INPUT); volume_id_encode_string(label, label_enc, sizeof(label_enc)); - set_str(uuid_safe, uuid, sizeof(uuid_safe)); - util_replace_chars(uuid_safe, ALLOWED_CHARS_INPUT); + udev_util_replace_whitespace(uuid, uuid_safe, sizeof(uuid_safe)); + udev_util_replace_chars(uuid_safe, UDEV_ALLOWED_CHARS_INPUT); volume_id_encode_string(uuid, uuid_enc, sizeof(uuid_enc)); volume_id_encode_string(type, type_enc, sizeof(type_enc)); |