X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=inline;f=cpmcp.c;h=590e702aa887177c06e7d39599a2b05dd7335162;hb=edf600144998d1a1e09898548938cc11b95c10bc;hp=7f1ff34a8184e446132a8c0d817a124dc4156355;hpb=da79766c5b4c4bae50ddc7bd81b610d3a45c5899;p=debian%2Fcpmtools diff --git a/cpmcp.c b/cpmcp.c index 7f1ff34..590e702 100644 --- a/cpmcp.c +++ b/cpmcp.c @@ -32,7 +32,7 @@ static int preserve=0; 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; } /*}}}*/ @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) /* 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; @@ -135,6 +135,7 @@ int main(int argc, char *argv[]) /*}}}*/ /* 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; @@ -216,7 +217,7 @@ int main(int argc, char *argv[]) FILE *ufp; /*}}}*/ - if ((ufp=fopen(argv[i],"r"))==(FILE*)0) /* cry a little */ /*{{{*/ + if ((ufp=fopen(argv[i],"rb"))==(FILE*)0) /* cry a little */ /*{{{*/ { fprintf(stderr,"%s: can not open %s: %s\n",cmd,argv[i],strerror(errno)); exitcode=1; @@ -225,16 +226,19 @@ int main(int argc, char *argv[]) else { struct cpmInode ino; - char cpmname[2+8+3+1]; /* 00foobarxy.zzy\0 */ + 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 */ /*{{{*/ { @@ -273,6 +277,13 @@ int main(int argc, char *argv[]) exitcode=1; } /*}}}*/ + if (preserve && !ohno) + { + struct utimbuf times; + times.actime=st.st_atime; + times.modtime=st.st_mtime; + cpmUtime(&ino,×); + } } fclose(ufp); }