#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <utime.h>
static int userNumber(const char *s) /*{{{*/
{
if (isdigit(*s) && *(s+1)==':') return (*s-'0');
- if (isdigit(*s) && isdigit(*(s+1)) && *(s+2)==':') return (10*(*s-'0')+(*(s+1)));
+ if (isdigit(*s) && isdigit(*(s+1)) && *(s+2)==':') return (10*(*s-'0')+(*(s+1)-'0'));
return -1;
}
/*}}}*/
int res;
char buf[4096];
- while ((res=cpmRead(&file,buf,sizeof(buf)))!=0)
+ while ((res=cpmRead(&file,buf,sizeof(buf)))>0)
{
int j;
}
}
endwhile:
+ if (res==-1 && !ohno) { fprintf(stderr,"%s: can not read %s (%s)\n",cmd,src,boo); exitcode=1; ohno=1; }
if (fclose(ufp)==EOF && !ohno) { fprintf(stderr,"%s: can not close %s: %s\n",cmd,dest,strerror(errno)); exitcode=1; ohno=1; }
if (preserve && !ohno && (ino.atime || ino.mtime))
{
/* variables */ /*{{{*/
const char *err;
const char *image;
- const char *format=FORMAT;
+ const char *format;
const char *devopts=NULL;
int c,readcpm=-1,todir=-1;
struct cpmInode root;
/*}}}*/
/* parse options */ /*{{{*/
+ if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
while ((c=getopt(argc,argv,"T:f:h?pt"))!=EOF) switch(c)
{
case 'T': devopts=optarg; break;
/* open image file */ /*{{{*/
if ((err=Device_open(&super.dev,image,readcpm ? O_RDONLY : O_RDWR, devopts)))
{
- fprintf(stderr,"%s: can not open %s (%s)\n",cmd,image,err);
+ fprintf(stderr,"%s: cannot open %s (%s)\n",cmd,image,err);
+ exit(1);
+ }
+ if (cpmReadSuper(&super,&root,format)==-1)
+ {
+ fprintf(stderr,"%s: cannot read superblock (%s)\n",cmd,boo);
exit(1);
}
- cpmReadSuper(&super,&root,format);
/*}}}*/
if (readcpm) /* copy from CP/M to UNIX */ /*{{{*/
{
{
struct cpmInode ino;
char cpmname[2+8+1+3+1]; /* 00foobarxy.zzy\0 */
+ struct stat st;
+
+ stat(argv[i],&st);
if (todir)
{
if ((dest=strrchr(argv[i],'/'))!=(char*)0) ++dest; else dest=argv[i];
- sprintf(cpmname,"%02d%s",userNumber(argv[argc-1]),dest);
+ snprintf(cpmname,sizeof(cpmname),"%02d%s",userNumber(argv[argc-1]),dest);
}
else
{
- sprintf(cpmname,"%02d%s",userNumber(argv[argc-1]),strchr(argv[argc-1],':')+1);
+ snprintf(cpmname,sizeof(cpmname),"%02d%s",userNumber(argv[argc-1]),strchr(argv[argc-1],':')+1);
}
if (cpmCreat(&root,cpmname,&ino,0666)==-1) /* just cry */ /*{{{*/
{
cpmOpen(&ino,&file,O_WRONLY);
do
{
- int j;
+ unsigned int j;
for (j=0; j<(sizeof(buf)/2) && (c=getc(ufp))!=EOF; ++j)
{
buf[j]=c;
}
if (text && c==EOF) buf[j++]='\032';
- if (cpmWrite(&file,buf,j)!=j)
+ if (cpmWrite(&file,buf,j)!=(ssize_t)j)
{
fprintf(stderr,"%s: can not write %s: %s\n",cmd,dest,boo);
ohno=1;
exitcode=1;
}
/*}}}*/
+ if (preserve && !ohno)
+ {
+ struct utimbuf times;
+ times.actime=st.st_atime;
+ times.modtime=st.st_mtime;
+ cpmUtime(&ino,×);
+ }
}
fclose(ufp);
}