4a5
>  * further   modifications by:  Robert Regn	   rtregn@faui32.uucp
8a10
> #include <stat.h>
31a34
> static char rdonly=0;
57c60,62
< 	filemess("");
---
> 	rdonly = (access(fname, 2) != 0);
> 	filemess( rdonly ? "[Read only]" : "");
> 	outstr("rdonly : ");
82c87,89
< 				exit(1);
---
> 				{outstr("\n\r");
> 				windexit(1);
> 				}
118c125
< 		p="\"%s\" %d lines, %ld characters (%d un-printable))";
---
> 		p="\"%s\" %s %d lines, %ld characters (%d un-printable))";
120c127
< 		p="\"%s\" %d lines, %ld characters";
---
> 		p="\"%s\" %s %d lines, %ld characters";
122c129
< 	sprintf(buff, p, fname, linecnt, nchars, unprint);
---
> 	sprintf(buff, p, fname, rdonly ? "[Read only]" : "", linecnt, nchars, unprint);
146a154,155
> 	struct stat sbuf;
> 	char newfile=1;
149a159,160
> 	if (stat(fname, &sbuf)!= 0)	/* save mode of file for creating */
> 		newfile = 1;
166c177,178
< 	rename(fname, backup);
---
> 	/* skipping rename avoids overwriting  R/O files by creating a new */
> 	/* also save link structure 			R. Regn*/
167a180,181
> 	if (!rdonly && sbuf.st_nlink == 1)
> 		rename(fname, backup);
168a183
> 
172c187,189
< 		emsg("Can't open file for writing!");
---
> 		if (rdonly)
> 			emsg("File is Read only");
> 		else 	emsg("Permission denied");
175a193,196
> 	if (!rdonly && !newfile)	/* restore mode (and owner) properly */
> 		{chmod(fname, sbuf.st_mode&04777);
> 		 chown (sbuf.st_uid, sbuf.st_gid);
> 		}
