From 52d61845d9053c77dc779c2102942f0fc4cdd73f Mon Sep 17 00:00:00 2001 From: springob Date: Fri, 22 Oct 2010 14:44:53 +0000 Subject: [PATCH] * 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 --- ser_posix.c | 18 +++++++++--------- ser_win32.c | 13 +++++++------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ser_posix.c b/ser_posix.c index accabb02..210bff20 100644 --- a/ser_posix.c +++ b/ser_posix.c @@ -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); } /* diff --git a/ser_win32.c b/ser_win32.c index 9d8bf7aa..4b55646b 100644 --- a/ser_win32.c +++ b/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; 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; }