diff options
| author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-12-23 20:37:23 +0000 |
|---|---|---|
| committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-12-23 20:37:23 +0000 |
| commit | 8bf477de1418513e38fb4e4f681078a26211536d (patch) | |
| tree | 51192e8c411160baaf9398955847902c5bcc548c /libbb | |
| parent | ba641c05366b81713ebfe44daca8ab3a6a490b72 (diff) | |
| download | busybox-w32-8bf477de1418513e38fb4e4f681078a26211536d.tar.gz busybox-w32-8bf477de1418513e38fb4e4f681078a26211536d.tar.bz2 busybox-w32-8bf477de1418513e38fb4e4f681078a26211536d.zip | |
don't mess up errno
git-svn-id: svn://busybox.net/trunk/busybox@8167 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/xconnect.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index b3619fd0e..10ba9477c 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
| @@ -27,9 +27,15 @@ unsigned short bb_lookup_port(const char *port, unsigned short default_port) | |||
| 27 | { | 27 | { |
| 28 | unsigned short port_nr = htons(default_port); | 28 | unsigned short port_nr = htons(default_port); |
| 29 | if (port) { | 29 | if (port) { |
| 30 | char *endptr; | 30 | char *endptr; |
| 31 | long port_long = strtol(port, &endptr, 10); | 31 | int old_errno; |
| 32 | long port_long; | ||
| 32 | 33 | ||
| 34 | /* Since this is a lib function, we're not allowed to reset errno to 0. | ||
| 35 | * Doing so could break an app that is deferring checking of errno. */ | ||
| 36 | old_errno = errno; | ||
| 37 | errno = 0; | ||
| 38 | port_long = strtol(port, &endptr, 10); | ||
| 33 | if (errno != 0 || *endptr!='\0' || endptr==port || port_long < 0 || port_long > 65535) { | 39 | if (errno != 0 || *endptr!='\0' || endptr==port || port_long < 0 || port_long > 65535) { |
| 34 | struct servent *tserv = getservbyname(port, "tcp"); | 40 | struct servent *tserv = getservbyname(port, "tcp"); |
| 35 | if (tserv) { | 41 | if (tserv) { |
| @@ -38,6 +44,7 @@ unsigned short bb_lookup_port(const char *port, unsigned short default_port) | |||
| 38 | } else { | 44 | } else { |
| 39 | port_nr = htons(port_long); | 45 | port_nr = htons(port_long); |
| 40 | } | 46 | } |
| 47 | errno = old_errno; | ||
| 41 | } | 48 | } |
| 42 | return port_nr; | 49 | return port_nr; |
| 43 | } | 50 | } |
