Fix ptsname_r(3) return type to match glibc

The gHardy man pages specify the return type of ptsname_r to be char*, but the
return value to be 0 on success, negative on error and the gHardy stdlib.h
defines extern int ptsname_r(...).

Busybox telnetd fails to run successfully without this change.
This commit is contained in:
Colin Cross 2010-01-12 12:58:12 -08:00
parent 0b5db51ea6
commit 6458c49c96
2 changed files with 9 additions and 7 deletions

View File

@ -132,7 +132,7 @@ static __inline__ void srandom(unsigned int __s)
extern int unlockpt(int);
extern char* ptsname(int);
extern char* ptsname_r(int, char*, size_t);
extern int ptsname_r(int, char*, size_t);
extern int getpt(void);
static __inline__ int grantpt(int __fd)

View File

@ -32,7 +32,7 @@
#include <errno.h>
#include <string.h>
char* ptsname_r( int fd, char* buf, size_t buflen)
int ptsname_r( int fd, char* buf, size_t buflen)
{
unsigned int pty_num;
char buff[64];
@ -40,17 +40,19 @@ char* ptsname_r( int fd, char* buf, size_t buflen)
if (buf == NULL) {
errno = EINVAL;
return NULL;
return -1;
}
if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 )
return NULL;
if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 ) {
errno = ENOTTY;
return -1;
}
len = snprintf( buff, sizeof(buff), "/dev/pts/%u", pty_num );
if (len+1 > (int)buflen) {
errno = ERANGE;
return NULL;
return -1;
}
memcpy( buf, buff, len+1 );
return buf;
return 0;
}