Index: dorandom.c =================================================================== --- dorandom.c (revision 2116) +++ dorandom.c (revision 2117) @@ -58,7 +58,7 @@ char *urand_get(int numbytes) { char *retval; - int result; + int n, result; retval=(char *)malloc(numbytes); if (!retval) { @@ -66,11 +66,13 @@ exit(1); /* sorry :-(. */ } - result=read(infile,retval,numbytes); - if (result < numbytes) { - free(retval); - return NULL; /* couldn't do it :-( */ + for (n = result = 0; result < numbytes; result += n) { + n = read(infile, retval + result, numbytes - result); + if (n <= 0) { + free(retval); + return NULL; + } } return retval; Index: aescmdline.c =================================================================== --- aescmdline.c (revision 2116) +++ aescmdline.c (revision 2117) @@ -33,13 +33,15 @@ /* write data, aborting if we have a write error. */ void ewrite(int outfile,void *buf, size_t count) { - int result; + int n, result; - result=write(outfile,buf,count); - if (result!=(int) count) { - fprintf(stderr,"%s:error:could not write data.\n",progname); - perror(progname); - usage(); + for (n = result = 0; result < count; result += n) { + n = write(outfile, buf + result, count - result); + if (n <= 0) { + fprintf(stderr,"%s:error:could not write data.\n",progname); + perror(progname); + usage(); + } } } @@ -80,13 +82,19 @@ */ void read_key_from_stdin(int infile, int keysize) { unsigned char keybuf[65]; - int result, hexkeysize; + int n, result, hexkeysize; hexkeysize = keysize / 4; - result=read(infile,keybuf, hexkeysize+1); - if (result