* 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:
springob 2010-10-22 14:44:53 +00:00
parent fcce4d2de3
commit 52d61845d9
2 changed files with 16 additions and 15 deletions

View File

@ -152,7 +152,7 @@ static int ser_setspeed(union filedescriptor *fd, long baud)
* terminal/console server with serial parameters configured
* appropriately (e. g. 115200-8-N-1 for a STK500.)
*/
static void
static int
net_open(const char *port, union filedescriptor *fdp)
{
char *hstr, *pstr, *end;
@ -164,14 +164,14 @@ net_open(const char *port, union filedescriptor *fdp)
if ((hstr = strdup(port)) == NULL) {
fprintf(stderr, "%s: net_open(): Out of memory!\n",
progname);
exit(1);
return -1;
}
if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) {
fprintf(stderr, "%s: net_open(): Mangled host:port string \"%s\"\n",
progname, 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",
progname, pstr);
free(hstr);
exit(1);
return -1;
}
if ((hp = gethostbyname(hstr)) == NULL) {
fprintf(stderr, "%s: net_open(): unknown host \"%s\"\n",
progname, hstr);
free(hstr);
exit(1);
return -1;
}
free(hstr);
@ -200,7 +200,7 @@ net_open(const char *port, union filedescriptor *fdp)
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "%s: net_open(): Cannot open socket: %s\n",
progname, strerror(errno));
exit(1);
return -1;
}
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))) {
fprintf(stderr, "%s: net_open(): Connect failed: %s\n",
progname, strerror(errno));
exit(1);
return -1;
}
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.
*/
if (strncmp(port, "net:", strlen("net:")) == 0) {
net_open(port + strlen("net:"), fdp);
return 0;
return net_open(port + strlen("net:"), fdp);
}
/*

View File

@ -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;
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"
"implemented for Win32 environments\n",
progname);
exit(1);
return -1;
}
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",
progname, port, (char*)lpMsgBuf);
LocalFree( lpMsgBuf );
exit(1);
return -1;
}
if (!SetupComm(hComPort, W32SERBUFSIZE, W32SERBUFSIZE))
@ -174,7 +174,7 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set buffers for \"%s\"\n",
progname, port);
exit(1);
return -1;
}
fdp->pfd = (void *)hComPort;
@ -183,7 +183,7 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set com-state for \"%s\"\n",
progname, port);
exit(1);
return -1;
}
if (!serial_w32SetTimeOut(hComPort,0))
@ -191,12 +191,13 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp)
CloseHandle(hComPort);
fprintf(stderr, "%s: ser_open(): can't set initial timeout for \"%s\"\n",
progname, port);
exit(1);
return -1;
}
if (newname != 0) {
free(newname);
}
return 0;
}