* serial_open() calls will now return -1 on error (no call to exit())
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@949 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
parent
fcce4d2de3
commit
52d61845d9
18
ser_posix.c
18
ser_posix.c
|
@ -152,7 +152,7 @@ static int ser_setspeed(union filedescriptor *fd, long baud)
|
||||||
* terminal/console server with serial parameters configured
|
* terminal/console server with serial parameters configured
|
||||||
* appropriately (e. g. 115200-8-N-1 for a STK500.)
|
* appropriately (e. g. 115200-8-N-1 for a STK500.)
|
||||||
*/
|
*/
|
||||||
static void
|
static int
|
||||||
net_open(const char *port, union filedescriptor *fdp)
|
net_open(const char *port, union filedescriptor *fdp)
|
||||||
{
|
{
|
||||||
char *hstr, *pstr, *end;
|
char *hstr, *pstr, *end;
|
||||||
|
@ -164,14 +164,14 @@ net_open(const char *port, union filedescriptor *fdp)
|
||||||
if ((hstr = strdup(port)) == NULL) {
|
if ((hstr = strdup(port)) == NULL) {
|
||||||
fprintf(stderr, "%s: net_open(): Out of memory!\n",
|
fprintf(stderr, "%s: net_open(): Out of memory!\n",
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) {
|
if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) {
|
||||||
fprintf(stderr, "%s: net_open(): Mangled host:port string \"%s\"\n",
|
fprintf(stderr, "%s: net_open(): Mangled host:port string \"%s\"\n",
|
||||||
progname, hstr);
|
progname, hstr);
|
||||||
free(hstr);
|
free(hstr);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -185,14 +185,14 @@ net_open(const char *port, union filedescriptor *fdp)
|
||||||
fprintf(stderr, "%s: net_open(): Bad port number \"%s\"\n",
|
fprintf(stderr, "%s: net_open(): Bad port number \"%s\"\n",
|
||||||
progname, pstr);
|
progname, pstr);
|
||||||
free(hstr);
|
free(hstr);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((hp = gethostbyname(hstr)) == NULL) {
|
if ((hp = gethostbyname(hstr)) == NULL) {
|
||||||
fprintf(stderr, "%s: net_open(): unknown host \"%s\"\n",
|
fprintf(stderr, "%s: net_open(): unknown host \"%s\"\n",
|
||||||
progname, hstr);
|
progname, hstr);
|
||||||
free(hstr);
|
free(hstr);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(hstr);
|
free(hstr);
|
||||||
|
@ -200,7 +200,7 @@ net_open(const char *port, union filedescriptor *fdp)
|
||||||
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
|
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
fprintf(stderr, "%s: net_open(): Cannot open socket: %s\n",
|
fprintf(stderr, "%s: net_open(): Cannot open socket: %s\n",
|
||||||
progname, strerror(errno));
|
progname, strerror(errno));
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sockaddr, 0, sizeof(struct sockaddr_in));
|
memset(&sockaddr, 0, sizeof(struct sockaddr_in));
|
||||||
|
@ -211,10 +211,11 @@ net_open(const char *port, union filedescriptor *fdp)
|
||||||
if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) {
|
if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) {
|
||||||
fprintf(stderr, "%s: net_open(): Connect failed: %s\n",
|
fprintf(stderr, "%s: net_open(): Connect failed: %s\n",
|
||||||
progname, strerror(errno));
|
progname, strerror(errno));
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdp->ifd = fd;
|
fdp->ifd = fd;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,8 +258,7 @@ static int ser_open(char * port, long baud, union filedescriptor *fdp)
|
||||||
* handle it as a TCP connection to a terminal server.
|
* handle it as a TCP connection to a terminal server.
|
||||||
*/
|
*/
|
||||||
if (strncmp(port, "net:", strlen("net:")) == 0) {
|
if (strncmp(port, "net:", strlen("net:")) == 0) {
|
||||||
net_open(port + strlen("net:"), fdp);
|
return net_open(port + strlen("net:"), fdp);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
13
ser_win32.c
13
ser_win32.c
|
@ -112,7 +112,7 @@ static int ser_setspeed(union filedescriptor *fd, long baud)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ser_open(char * port, long baud, union filedescriptor *fdp)
|
static int ser_open(char * port, long baud, union filedescriptor *fdp)
|
||||||
{
|
{
|
||||||
LPVOID lpMsgBuf;
|
LPVOID lpMsgBuf;
|
||||||
HANDLE hComPort=INVALID_HANDLE_VALUE;
|
HANDLE hComPort=INVALID_HANDLE_VALUE;
|
||||||
|
@ -129,7 +129,7 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
|
||||||
"%s: ser_open(): network connects are currently not"
|
"%s: ser_open(): network connects are currently not"
|
||||||
"implemented for Win32 environments\n",
|
"implemented for Win32 environments\n",
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncasecmp(port, "com", strlen("com")) == 0) {
|
if (strncasecmp(port, "com", strlen("com")) == 0) {
|
||||||
|
@ -166,7 +166,7 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
|
||||||
fprintf(stderr, "%s: ser_open(): can't open device \"%s\": %s\n",
|
fprintf(stderr, "%s: ser_open(): can't open device \"%s\": %s\n",
|
||||||
progname, port, (char*)lpMsgBuf);
|
progname, port, (char*)lpMsgBuf);
|
||||||
LocalFree( lpMsgBuf );
|
LocalFree( lpMsgBuf );
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
|
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
|
||||||
|
@ -174,7 +174,7 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
|
||||||
CloseHandle(hComPort);
|
CloseHandle(hComPort);
|
||||||
fprintf(stderr, "%s: ser_open(): can't set buffers for \"%s\"\n",
|
fprintf(stderr, "%s: ser_open(): can't set buffers for \"%s\"\n",
|
||||||
progname, port);
|
progname, port);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdp->pfd = (void *)hComPort;
|
fdp->pfd = (void *)hComPort;
|
||||||
|
@ -183,7 +183,7 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
|
||||||
CloseHandle(hComPort);
|
CloseHandle(hComPort);
|
||||||
fprintf(stderr, "%s: ser_open(): can't set com-state for \"%s\"\n",
|
fprintf(stderr, "%s: ser_open(): can't set com-state for \"%s\"\n",
|
||||||
progname, port);
|
progname, port);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!serial_w32SetTimeOut(hComPort,0))
|
if (!serial_w32SetTimeOut(hComPort,0))
|
||||||
|
@ -191,12 +191,13 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
|
||||||
CloseHandle(hComPort);
|
CloseHandle(hComPort);
|
||||||
fprintf(stderr, "%s: ser_open(): can't set initial timeout for \"%s\"\n",
|
fprintf(stderr, "%s: ser_open(): can't set initial timeout for \"%s\"\n",
|
||||||
progname, port);
|
progname, port);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newname != 0) {
|
if (newname != 0) {
|
||||||
free(newname);
|
free(newname);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue