diff options
author | ed <ed@FreeBSD.org> | 2013-05-25 12:13:54 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2013-05-25 12:13:54 +0000 |
commit | dcb48cfa2b59c0d7067b7107f4f8695e2519758a (patch) | |
tree | 82800a1975d4411b2bfb2e8128c26e8a719520ab /lib/libc/iconv | |
parent | 3f589c4a65061002236515a5e50d5eafb6c1f50f (diff) | |
download | FreeBSD-src-dcb48cfa2b59c0d7067b7107f4f8695e2519758a.zip FreeBSD-src-dcb48cfa2b59c0d7067b7107f4f8695e2519758a.tar.gz |
Make some tiny improvements to iconv_open().
- Remove an unneeded variable.
- Fix whitespace bugs.
- Fix typoes in comment.
- Improve string handling a bit. Don't handroll strstr() and don't
terminate a strdup()'ed string. Instead, simply strndup() the part we
need.
Diffstat (limited to 'lib/libc/iconv')
-rw-r--r-- | lib/libc/iconv/iconv.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/lib/libc/iconv/iconv.c b/lib/libc/iconv/iconv.c index d1e01e8..99cfc37 100644 --- a/lib/libc/iconv/iconv.c +++ b/lib/libc/iconv/iconv.c @@ -66,37 +66,31 @@ iconv_t _iconv_open(const char *out, const char *in, struct _citrus_iconv *prealloc); iconv_t -_iconv_open(const char *out, const char *in, struct _citrus_iconv *prealloc) +_iconv_open(const char *out, const char *in, struct _citrus_iconv *handle) { - struct _citrus_iconv *handle; - char *out_truncated, *p; + const char *out_slashes; + char *out_noslashes; int ret; - handle = prealloc; - /* * Remove anything following a //, as these are options (like * //ignore, //translate, etc) and we just don't handle them. - * This is for compatibilty with software that uses thees + * This is for compatibility with software that uses these * blindly. */ - out_truncated = strdup(out); - if (out_truncated == NULL) { - errno = ENOMEM; - return ((iconv_t)-1); + out_slashes = strstr(out, "//"); + if (out_slashes != NULL) { + out_noslashes = strndup(out, out_slashes - out); + if (out_noslashes == NULL) { + errno = ENOMEM; + return ((iconv_t)-1); + } + ret = _citrus_iconv_open(&handle, in, out_noslashes); + free(out_noslashes); + } else { + ret = _citrus_iconv_open(&handle, in, out); } - p = out_truncated; - while (*p != 0) { - if (p[0] == '/' && p[1] == '/') { - *p = '\0'; - break; - } - p++; - } - - ret = _citrus_iconv_open(&handle, in, out_truncated); - free(out_truncated); if (ret) { errno = ret == ENOENT ? EINVAL : ret; return ((iconv_t)-1); |