if ((gp->dwn_file = open(gp->file_name, O_RDWR | O_CREAT, 0666)) == -1) { sprintf(s, "Unable to open %s", gp->file_name); statline(mode, s); if (write(fd, "#ABORT#\r", 8) == -1) { perror("write"); gp->dwn_cnt = 0; gp->file_name[0] = '\0'; return -1;
if ((gp->dwn_file = open(gp->file_name, O_RDWR | O_CREAT, 0666)) == -1) { sprintf(s, "Unable to open %s", gp->file_name); statline(mode, s); if (write(fd, "#ABORT#\r", 8) == -1) { perror("write"); gp->dwn_cnt = 0; gp->file_name[0] = '\0'; return -1; }
int start_ab_download(int mode, WINDOW ** swin, wint * wintab, char parms[], int parmsbytes, char buf[], int bytes, t_gp * gp, char *address[]){    int crcst;			/* startposition crc-field  */    int datest = 0;		/* startposition date-field */    int namest = 0;		/* startposition name-field */    int cnt;    int date = 0;    struct tm ft;    char s[80];    for (crcst = 2; (!(parms[crcst - 2] == '#'		       && parms[crcst - 1] == '|')		     && crcst < parmsbytes - 1); crcst++);    if (crcst < parmsbytes - 1) {	gp->file_crc = atoi(parms + crcst);	for (datest = crcst; (!(parms[datest - 2] == '#'				&& parms[datest - 1] == '$')); datest++);	date = (int) strtol(parms + datest, NULL, 16);	ft.tm_sec = (date & 0x1F) * 2;	date >>= 5;	ft.tm_min = date & 0x3F;	date >>= 6;	ft.tm_hour = date & 0x1F;	date >>= 5;	ft.tm_mday = date & 0x1F;	date >>= 5;	ft.tm_mon = date & 0x0F;	date >>= 4;	ft.tm_year = (date & 0x7F) + 70;	ft.tm_isdst = 0;	ft.tm_yday = 0;	ft.tm_wday = 0;	gp->ut.actime = mktime(&ft);	gp->ut.modtime = gp->ut.actime;	for (namest = datest; (parms[namest - 1] != '#' &&			       namest < parmsbytes - 1); namest++);    } else {	gp->ut.actime = 0;	gp->ut.modtime = 0;    }    gp->dwn_cnt = atol(parms);    strcpy(gp->file_name, STD_DWN_DIR);    if (crcst == parmsbytes - 1 || datest - crcst > 7 || namest - datest > 10) {	*swin = opnstatw(mode, wintab, "Remote starts AutoBin transfer", 6, 52);	gp->new_header = FALSE;	wrdstatw(*swin, "old styled Header (no filename)");	strcat(gp->file_name, address[0]);	strcat(gp->file_name, ".dwnfile");    } else {	*swin = opnstatw(mode, wintab, "Remote starts AutoBin transfer", 10, 52);	gp->new_header = TRUE;	for (cnt = parmsbytes - namest; !(parms[cnt + namest - 1] == '\\' || parms[cnt + namest - 1] == '/') && cnt > 0; cnt--);	strncpy(s, &parms[namest + cnt], parmsbytes - namest - cnt);	convert_upper_lower(s, parmsbytes - namest - cnt);	strncat(gp->file_name, s, parmsbytes - namest - cnt);	gp->file_name[strlen(gp->file_name) + parmsbytes - namest - cnt - 1] = 0;	sprintf(s, "size of file    : %u", (unsigned int) gp->dwn_cnt);	wrdstatw(*swin, s);	sprintf(s, "filename        : %s", gp->file_name);	wrdstatw(*swin, s);	sprintf(s, "last mod. date  : %02i.%02i.%04i", ft.tm_mday, ft.tm_mon, ft.tm_year + 1900);	wrdstatw(*swin, s);	sprintf(s, "last mod. time  : %02i:%02i:%02i", ft.tm_hour, ft.tm_min, ft.tm_sec);	wrdstatw(*swin, s);    }    dupdstatw(*swin, "Bytes to receive: ", TRUE);    if ((gp->dwn_file = open(gp->file_name, O_RDWR | O_CREAT, 0666)) == -1) {	sprintf(s, "Unable to open %s", gp->file_name);	statline(mode, s);	if (write(fd, "#ABORT#\r", 8) == -1) {	    perror("write");	    gp->dwn_cnt = 0;	    gp->file_name[0] = '\0';	    return -1;	}    }    if (bytes == 1) {	if (write(fd, "#OK#\r", 5) == -1) {	    perror("write");	    gp->dwn_cnt = 0;	    gp->file_name[0] = '\0';	    return -1;	}	gp->calc_crc = 0;    } else {	write(gp->dwn_file, buf, bytes);	gp->calc_crc = calc_crc(buf, bytes, 0);	gp->dwn_cnt -= bytes;    }    return 0;}