/* #includes */ /*{{{C}}}*//*{{{*/
+#include "config.h"
+
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "config.h"
-#include "getopt.h"
+#include "getopt_.h"
#include "cpmfs.h"
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
/*}}}*/
const char cmd[]="cpmchattr";
/* variables */ /*{{{*/
const char *err;
const char *image;
- const char *format=FORMAT;
+ const char *format;
const char *devopts=NULL;
int c,i,usage=0,exitcode=0;
struct cpmSuperBlock drive;
/*}}}*/
/* parse options */ /*{{{*/
+ if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
while ((c=getopt(argc,argv,"T:f:h?"))!=EOF) switch(c)
{
case 'T': devopts=optarg; break;
if (optind>=(argc-2)) usage=1;
else
{
- image=argv[optind];
- attrs = argv[optind+1];
+ image=argv[optind++];
+ attrs = argv[optind++];
}
if (usage)
/* open image */ /*{{{*/
if ((err=Device_open(&drive.dev, image, 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(&drive,&root,format)==-1)
+ {
+ fprintf(stderr,"%s: cannot read superblock (%s)\n",cmd,boo);
exit(1);
}
- cpmReadSuper(&drive,&root,format);
/*}}}*/
cpmglob(optind,argc,argv,&root,&gargc,&gargv);
for (i=0; i<gargc; ++i)
{
struct cpmInode ino;
- int err;
+ int rc;
cpm_attr_t attrib;
- err = cpmNamei(&root,gargv[i], &ino)==-1;
- if (!err) err = cpmAttrGet(&ino, &attrib);
- if (!err)
+ rc = cpmNamei(&root,gargv[i], &ino)==-1;
+ if (!rc) rc = cpmAttrGet(&ino, &attrib);
+ if (!rc)
{
- int n, m;
+ unsigned int n;
+ int m;
+
m = 0;
for (n = 0; n < strlen(attrs); n++)
{
}
if (m) attrib &= ~mask; else attrib |= mask;
}
- err = cpmAttrSet(&ino, attrib);
+ rc = cpmAttrSet(&ino, attrib);
}
- if (err)
+ if (rc)
{
fprintf(stderr,"%s: can not set attributes for %s: %s\n",cmd,gargv[i],boo);
exitcode=1;
}
}
+ cpmUmount(&drive);
exit(exitcode);
}
/*}}}*/