Compare commits

...

5 commits

Author SHA1 Message Date
33c86ceca2 tclhfs & hfswish: Get rid of use of interp->result
Direct access to interp->result has been deprecated for a long
time. Fix it.

 * Where the result is being read, use Tcl_GetStringResult
 * Where the result is being written, use Tcl_SetResult
   * Where it is being written from a printf format string, use
     a wrapper function "resultf".
   * In each case, ensure the correct free function is
     passed (static, dynamic, or volatile)
2025-08-18 10:38:16 -05:00
df8a1fcc25 os.c: Add explicit casts
A Unix file descriptor number is stored in the
"generic callback argument" `void **priv`. However, on LP64
systems like x86_64 linux, `int` and `void **` have different size.
This leads to a compiler diagnostic:
```
os.c: In function ‘os_write’:
os.c:192:12: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  192 |   int fd = (int) *priv;
      |            ^
```
Adding an additional cast via `intptr_t` resolves the compiler
diagnostics.
2025-08-18 08:38:15 -05:00
94f6cd0004 tclhfs.c: Fix another alloc/free mismatch.
fargv is allocated by hfs_glob so it must be freed by free, not Tcl_Free.

```
1036           fargv = hfs_glob(vol, listc, listv, &fargc);
```
2025-08-18 08:38:15 -05:00
Zixing Liu
8df708921d Fix cv-qualifiers for GCC 14.1
GCC 14 now enforces strict cv-qualifier check by default.
This patch fixes all the cv-qualifier violations.

This change is adapted from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1075067
2025-08-18 08:38:15 -05:00
Zixing Liu
c68e5fb6a7 tclhfs.c: Fix another alloc/free mismatch.
The allocation on line 1032 is created via Tcl_SplitList,
and so it must be freed with Tcl_Free rather than bare free.
```
1032           if (Tcl_SplitList(interp, argv[2], &listc, &listv) != TCL_OK)
```

This change is adapted from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1075067
2025-08-18 08:38:12 -05:00
35 changed files with 172 additions and 135 deletions

View file

@ -127,7 +127,7 @@ char *latin1_subst[128] = {
* NAME: charset->unicode()
* DESCRIPTION: return a Unicode string for MacOS Standard Roman
*/
UCS2 *cs_unicode(char *mstr, int *lenptr)
UCS2 *cs_unicode(const char *mstr, int *lenptr)
{
int len, i;
UCS2 *unicode, *ptr;
@ -151,7 +151,7 @@ UCS2 *cs_unicode(char *mstr, int *lenptr)
* NAME: charset->latin1()
* DESCRIPTION: return a Latin-1 (ISO 8859-1) string for MacOS Standard Roman
*/
char *cs_latin1(char *mstr, int *lenptr)
char *cs_latin1(const char *mstr, int *lenptr)
{
int ilen, olen, i;
char *latin1, *ptr;
@ -229,7 +229,7 @@ void mktable(void)
* NAME: charset->macroman()
* DESCRIPTION: return a MacOS Standard Roman string for Latin-1 (ISO 8859-1)
*/
char *cs_macroman(char *lstr, int *lenptr)
char *cs_macroman(const char *lstr, int *lenptr)
{
int ilen, olen, i;
char *macroman, *ptr;

View file

@ -21,7 +21,7 @@
typedef unsigned short UCS2;
UCS2 *cs_unicode(char *, int *);
UCS2 *cs_unicode(const char *, int *);
char *cs_latin1(char *, int *);
char *cs_macroman(char *, int *);
char *cs_latin1(const char *, int *);
char *cs_macroman(const char *, int *);

2
glob.c
View file

@ -336,7 +336,7 @@ int doglob(hfsvol *vol, dlist *list, const char *dir, const char *rem)
* NAME: hfs->glob()
* DESCRIPTION: perform glob pattern matching
*/
char **hfs_glob(hfsvol *vol, int argc, char *argv[], int *nelts)
char **hfs_glob(hfsvol *vol, int argc, const char *argv[], int *nelts)
{
dlist list;
int i;

2
glob.h
View file

@ -19,4 +19,4 @@
* $Id: glob.h,v 1.6 1998/04/11 08:26:55 rob Exp $
*/
char **hfs_glob(hfsvol *, int, char *[], int *);
char **hfs_glob(hfsvol *, int, const char *[], int *);

View file

@ -51,7 +51,7 @@ int usage(void)
* NAME: hattrib->main()
* DESCRIPTION: implement hattrib command
*/
int hattrib_main(int argc, char *argv[])
int hattrib_main(int argc, const char *argv[])
{
const char *type = 0, *crea = 0;
int invis = 0, lock = 0, bless = 0;

View file

@ -19,4 +19,4 @@
* $Id: hattrib.h,v 1.6 1998/04/11 08:26:56 rob Exp $
*/
int hattrib_main(int, char *[]);
int hattrib_main(int, const char *[]);

2
hcd.c
View file

@ -36,7 +36,7 @@
* NAME: hcd->main()
* DESCRIPTION: implement hcd command
*/
int hcd_main(int argc, char *argv[])
int hcd_main(int argc, const char *argv[])
{
mountent *ment;
hfsvol *vol;

2
hcd.h
View file

@ -19,4 +19,4 @@
* $Id: hcd.h,v 1.7 1998/04/11 08:26:56 rob Exp $
*/
int hcd_main(int, char *[]);
int hcd_main(int, const char *[]);

View file

@ -252,7 +252,7 @@ int usage(void)
* NAME: hcopy->main()
* DESCRIPTION: implement hcopy command
*/
int hcopy_main(int argc, char *argv[])
int hcopy_main(int argc, const char *argv[])
{
int nargs, mode = 'a', result = 0;
const char *target;
@ -265,7 +265,7 @@ int hcopy_main(int argc, char *argv[])
{
int opt;
opt = getopt(argc, argv, "mbtra");
opt = getopt(argc, (char**)argv, "mbtra");
if (opt == EOF)
break;
@ -294,7 +294,7 @@ int hcopy_main(int argc, char *argv[])
copy = do_copyin;
fargc = nargs - 1;
fargv = &argv[optind];
fargv = (char**)&argv[optind];
}
else
{
@ -311,7 +311,7 @@ int hcopy_main(int argc, char *argv[])
hfsutil_unmount(vol, &result);
if (fargv && fargv != &argv[optind])
if (fargv && fargv != (char**)&argv[optind])
free(fargv);
return result;

View file

@ -19,4 +19,4 @@
* $Id: hcopy.h,v 1.6 1998/04/11 08:26:56 rob Exp $
*/
int hcopy_main(int, char *[]);
int hcopy_main(int, const char *[]);

2
hdel.c
View file

@ -35,7 +35,7 @@
* NAME: hdel->main()
* DESCRIPTION: implement hdel command
*/
int hdel_main(int argc, char *argv[])
int hdel_main(int argc, const char *argv[])
{
hfsvol *vol;
int fargc;

2
hdel.h
View file

@ -19,4 +19,4 @@
* $Id: hdel.h,v 1.6 1998/04/11 08:26:57 rob Exp $
*/
int hdel_main(int, char *[]);
int hdel_main(int, const char *[]);

View file

@ -75,7 +75,7 @@ hfsvol *do_format(const char *path, int partno, int mode, const char *vname)
* NAME: hformat->main()
* DESCRIPTION: implement hformat command
*/
int hformat_main(int argc, char *argv[])
int hformat_main(int argc, const char *argv[])
{
const char *vname;
char *path = 0;
@ -89,7 +89,7 @@ int hformat_main(int argc, char *argv[])
{
int opt;
opt = getopt(argc, argv, "fl:");
opt = getopt(argc, (char**)argv, "fl:");
if (opt == EOF)
break;

View file

@ -19,4 +19,4 @@
* $Id: hformat.h,v 1.7 1998/04/11 08:26:57 rob Exp $
*/
int hformat_main(int, char *[]);
int hformat_main(int, const char *[]);

View file

@ -64,14 +64,14 @@ const char *argv0, *bargv0;
* NAME: main()
* DESCRIPTION: program entry dispatch
*/
int main(int argc, char *argv[])
int main(int argc, const char *argv[])
{
int i, len;
const char *dot;
struct {
const char *name;
int (*func)(int, char *[]);
int (*func)(int, const char *[]);
} list[] = {
{ "hattrib", hattrib_main },
{ "hcd", hcd_main },
@ -254,7 +254,7 @@ void hfsutil_pinfo(hfsvolent *ent)
* NAME: hfsutil->glob()
* DESCRIPTION: perform filename globbing
*/
char **hfsutil_glob(hfsvol *vol, int argc, char *argv[],
char **hfsutil_glob(hfsvol *vol, int argc, const char *argv[],
int *nelts, int *result)
{
char **fargv;
@ -276,7 +276,7 @@ char **hfsutil_glob(hfsvol *vol, int argc, char *argv[],
char *hfsutil_getcwd(hfsvol *vol)
{
char *path, name[HFS_MAX_FLEN + 1 + 1];
long cwd;
unsigned long cwd;
int pathlen;
path = malloc(1);

View file

@ -32,7 +32,7 @@ hfsvol *hfsutil_remount(mountent *, int);
void hfsutil_unmount(hfsvol *, int *);
void hfsutil_pinfo(hfsvolent *);
char **hfsutil_glob(hfsvol *, int, char *[], int *, int *);
char **hfsutil_glob(hfsvol *, int, const char *[], int *, int *);
char *hfsutil_getcwd(hfsvol *);
int hfsutil_samepath(const char *, const char *);

View file

@ -94,7 +94,7 @@ int Tcl_AppInit(Tcl_Interp *interp)
if (Tcl_Eval(interp, xhfs) == TCL_ERROR)
{
fprintf(stderr, "Error: %s\n", interp->result);
fprintf(stderr, "Error: %s\n", Tcl_GetStringResult(interp));
exit(1);
}

4
hls.c
View file

@ -828,7 +828,7 @@ int queuepath(hfsvol *vol, char *path, darray *dirs, darray *files, int flags)
* NAME: hls->main()
* DESCRIPTION: implement hls command
*/
int hls_main(int argc, char *argv[])
int hls_main(int argc, const char *argv[])
{
hfsvol *vol;
int fargc, i;
@ -871,7 +871,7 @@ int hls_main(int argc, char *argv[])
{
int opt;
opt = getopt(argc, argv, "1abcdfilmqrstxw:CFNQRSU");
opt = getopt(argc, (char**)argv, "1abcdfilmqrstxw:CFNQRSU");
if (opt == EOF)
break;

2
hls.h
View file

@ -19,4 +19,4 @@
* $Id: hls.h,v 1.6 1998/04/11 08:26:58 rob Exp $
*/
int hls_main(int, char *[]);
int hls_main(int, const char *[]);

View file

@ -35,7 +35,7 @@
* NAME: hmkdir->main()
* DESCRIPTION: implement hmkdir command
*/
int hmkdir_main(int argc, char *argv[])
int hmkdir_main(int argc, const char *argv[])
{
hfsvol *vol;
char **fargv;

View file

@ -19,4 +19,4 @@
* $Id: hmkdir.h,v 1.6 1998/04/11 08:26:58 rob Exp $
*/
int hmkdir_main(int, char *[]);
int hmkdir_main(int, const char *[]);

View file

@ -36,7 +36,7 @@
* NAME: hmount->main()
* DESCRIPTION: implement hmount command
*/
int hmount_main(int argc, char *argv[])
int hmount_main(int argc, const char *argv[])
{
char *path = 0;
hfsvol *vol;

View file

@ -19,4 +19,4 @@
* $Id: hmount.h,v 1.7 1998/04/11 08:26:59 rob Exp $
*/
int hmount_main(int, char *[]);
int hmount_main(int, const char *[]);

2
hpwd.c
View file

@ -35,7 +35,7 @@
* NAME: hpwd->main()
* DESCRIPTION: implement hpwd command
*/
int hpwd_main(int argc, char *argv[])
int hpwd_main(int argc, const char *argv[])
{
mountent *ent;

2
hpwd.h
View file

@ -19,4 +19,4 @@
* $Id: hpwd.h,v 1.7 1998/04/11 08:26:59 rob Exp $
*/
int hpwd_main(int, char *[]);
int hpwd_main(int, const char *[]);

View file

@ -67,7 +67,7 @@ int do_rename(hfsvol *vol, int argc, char *argv[], const char *dest)
* NAME: hrename->main()
* DESCRIPTION: implement hrename command
*/
int hrename_main(int argc, char *argv[])
int hrename_main(int argc, const char *argv[])
{
mountent *ment;
hfsvol *vol;

View file

@ -19,4 +19,4 @@
* $Id: hrename.h,v 1.6 1998/04/11 08:26:59 rob Exp $
*/
int hrename_main(int, char *[]);
int hrename_main(int, const char *[]);

View file

@ -35,7 +35,7 @@
* NAME: hrmdir->main()
* DESCRIPTION: implement hrmdir command
*/
int hrmdir_main(int argc, char *argv[])
int hrmdir_main(int argc, const char *argv[])
{
hfsvol *vol;
char **fargv;

View file

@ -19,4 +19,4 @@
* $Id: hrmdir.h,v 1.6 1998/04/11 08:26:59 rob Exp $
*/
int hrmdir_main(int, char *[]);
int hrmdir_main(int, const char *[]);

View file

@ -35,7 +35,7 @@
* NAME: humount->main()
* DESCRIPTION: implement humount command
*/
int humount_main(int argc, char *argv[])
int humount_main(int argc, const char *argv[])
{
int vnum;
mountent *ent;

View file

@ -19,4 +19,4 @@
* $Id: humount.h,v 1.6 1998/04/11 08:26:59 rob Exp $
*/
int humount_main(int, char *[]);
int humount_main(int, const char *[]);

2
hvol.c
View file

@ -64,7 +64,7 @@ int showvol(mountent *ment)
* NAME: hvol->main()
* DESCRIPTION: implement hvol command
*/
int hvol_main(int argc, char *argv[])
int hvol_main(int argc, const char *argv[])
{
int vnum;
mountent *ment;

2
hvol.h
View file

@ -19,4 +19,4 @@
* $Id: hvol.h,v 1.7 1998/04/11 08:27:00 rob Exp $
*/
int hvol_main(int, char *[]);
int hvol_main(int, const char *[]);

View file

@ -88,7 +88,7 @@ int os_open(void **priv, const char *path, int mode)
(errno == EACCES || errno == EAGAIN))
ERROR(EAGAIN, "unable to obtain lock for medium");
*priv = (void *) fd;
*priv = (void *)(intptr_t) fd;
return 0;
@ -105,7 +105,7 @@ fail:
*/
int os_close(void **priv)
{
int fd = (int) *priv;
int fd = (int)(intptr_t) *priv;
*priv = (void *) -1;
@ -124,7 +124,7 @@ fail:
*/
int os_same(void **priv, const char *path)
{
int fd = (int) *priv;
int fd = (int)(intptr_t) *priv;
struct stat fdev, dev;
if (fstat(fd, &fdev) == -1 ||
@ -144,7 +144,7 @@ fail:
*/
unsigned long os_seek(void **priv, unsigned long offset)
{
int fd = (int) *priv;
int fd = (int)(intptr_t) *priv;
off_t result;
/* offset == -1 special; seek to last block of device */
@ -169,7 +169,7 @@ fail:
*/
unsigned long os_read(void **priv, void *buf, unsigned long len)
{
int fd = (int) *priv;
int fd = (int)(intptr_t) *priv;
ssize_t result;
result = read(fd, buf, len << HFS_BLOCKSZ_BITS);
@ -189,7 +189,7 @@ fail:
*/
unsigned long os_write(void **priv, const void *buf, unsigned long len)
{
int fd = (int) *priv;
int fd = (int)(intptr_t) *priv;
ssize_t result;
result = write(fd, buf, len << HFS_BLOCKSZ_BITS);

205
tclhfs.c
View file

@ -76,6 +76,39 @@ typedef struct {
Tcl_HashTable volumes; /* set containing mounted volumes (no values) */
Tcl_HashTable files; /* mapping of frefs -> vrefs */
/*
* NAME: resultf()
* DESCRIPTION: Fill the interpreter result using a printf-style format specifier
* NOTES: Requires a C99-conforming snprintf implemnetation
*/
#if __GNUC__
static
void resultf(Tcl_Interp *interp, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
#endif
static
void resultf(Tcl_Interp *interp, const char *fmt, ...)
{
char smallbuf[60];
int required;
va_list ap;
va_start(ap, fmt);
required = vsnprintf(smallbuf, sizeof(smallbuf), fmt, ap) + 1; // returned size does not include trailing NUL
va_end(ap);
if (required < sizeof(smallbuf)) {
Tcl_SetResult(interp, smallbuf, TCL_VOLATILE);
return;
}
char *buf = Tcl_Alloc(required);
va_start(ap, fmt);
vsnprintf(buf, required, fmt, ap);
va_end(ap);
Tcl_SetResult(interp, buf, TCL_DYNAMIC);
}
/*
* NAME: error()
* DESCRIPTION: return a Tcl error for an HFS error
@ -119,7 +152,7 @@ char *direntstr(hfsdirent *ent)
mddate[CHARLEN(long) + 1],
bkdate[CHARLEN(long) + 1];
register int argc;
char *argv[24];
const char *argv[24];
int locked, invis;
argc = 0;
@ -238,7 +271,7 @@ int getdir(Tcl_Interp *interp, volref *vref, const char *path)
str = direntstr(&ent);
if (str == 0)
{
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -275,7 +308,7 @@ void file_del(ClientData clientData)
*/
static
int file_cmd(ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
int argc, const char *argv[])
{
fileref *fref = clientData;
hfsfile *file = fref->file;
@ -283,7 +316,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
switch (argc)
{
case 1:
interp->result = "missing command";
Tcl_SetResult(interp, "missing command", TCL_STATIC);
return TCL_ERROR;
case 2:
@ -301,7 +334,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
if (offset == -1)
return error(interp, 0);
sprintf(interp->result, "%lu", offset);
resultf(interp, "%lu", offset);
}
else if (strcmp(argv[1], "stat") == 0)
{
@ -314,7 +347,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
str = direntstr(&ent);
if (str == 0)
{
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -322,7 +355,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
}
else if (strcmp(argv[1], "getfork") == 0)
{
interp->result = (hfs_getfork(file) == 0) ? "data" : "rsrc";
Tcl_SetResult(interp, (hfs_getfork(file) == 0) ? "data" : "rsrc", TCL_STATIC);
}
else
{
@ -345,7 +378,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
fork = 1;
else
{
interp->result = "bad arg to setfork: must be data or rsrc";
Tcl_SetResult(interp, "bad arg to setfork: must be data or rsrc", TCL_STATIC);
return TCL_ERROR;
}
@ -362,7 +395,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
if (offset == -1)
return error(interp, 0);
sprintf(interp->result, "%lu", offset);
resultf(interp, "%lu", offset);
}
else if (strcmp(argv[1], "read") == 0)
{
@ -374,7 +407,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
if (bytes < 0)
{
interp->result = "size must be >= 0";
Tcl_SetResult(interp, "size must be >= 0", TCL_STATIC);
return TCL_ERROR;
}
@ -399,7 +432,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
if (bytes == -1)
return error(interp, 0);
sprintf(interp->result, "%lu", bytes);
resultf(interp, "%lu", bytes);
}
else
{
@ -428,7 +461,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
whence = HFS_SEEK_END;
else
{
interp->result = "bad arg 3: must be start, current, or end";
Tcl_SetResult(interp, "bad arg 3: must be start, current, or end", TCL_STATIC);
return TCL_ERROR;
}
@ -436,7 +469,7 @@ int file_cmd(ClientData clientData, Tcl_Interp *interp,
if (offset == -1)
return error(interp, 0);
sprintf(interp->result, "%lu", offset);
resultf(interp, "%lu", offset);
}
else
{
@ -486,6 +519,7 @@ int fork_native(Tcl_Interp *interp, hfsfile *ifile, hfsfile *ofile)
/*
* NAME: file->ref()
* DESCRIPTION: called to initialize a new file reference
* NOTE: Sets interpreter result to the new command name
*/
static
void file_ref(Tcl_Interp *interp, volref *vref, fileref *fref, hfsfile *file)
@ -495,17 +529,18 @@ void file_ref(Tcl_Interp *interp, volref *vref, fileref *fref, hfsfile *file)
Tcl_HashEntry *entry;
int new;
char buf[sizeof("hfsfile") + sizeof(int) * 3];
do
sprintf(interp->result, "hfsfile%d", id++);
while (Tcl_GetCommandInfo(interp, interp->result, &info));
snprintf(buf, sizeof(buf), "hfsfile%d", id++);
while (Tcl_GetCommandInfo(interp, buf, &info));
fref->file = file;
fref->interp = interp;
fref->cmd = Tcl_CreateCommand(interp, interp->result,
file_cmd, fref, file_del);
fref->cmd = Tcl_CreateCommand(interp, buf, file_cmd, fref, file_del);
entry = Tcl_CreateHashEntry(&files, (char *) fref, &new);
Tcl_SetHashValue(entry, vref);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
}
/*
@ -541,7 +576,7 @@ int do_copynative(Tcl_Interp *interp, hfsfile *ifile, hfsfile *ofile)
* DESCRIPTION: copy an HFS file to another HFS volume
*/
static
int copynative(Tcl_Interp *interp, volref *srcvref, char *argv[])
int copynative(Tcl_Interp *interp, volref *srcvref, const char *argv[])
{
volref *dstvref;
Tcl_CmdInfo info;
@ -612,7 +647,7 @@ int copynative(Tcl_Interp *interp, volref *srcvref, char *argv[])
if (srcvref->vol == dstvref->vol &&
ent.cnid == cnid)
{
interp->result = "source and destination files are the same";
Tcl_SetResult(interp, "source and destination files are the same", TCL_STATIC);
hfs_close(ifile);
return TCL_ERROR;
}
@ -649,7 +684,7 @@ int copynative(Tcl_Interp *interp, volref *srcvref, char *argv[])
* DESCRIPTION: copy a UNIX file into an HFS volume
*/
static
int copyin(Tcl_Interp *interp, hfsvol *vol, char *argv[])
int copyin(Tcl_Interp *interp, hfsvol *vol, const char *argv[])
{
cpifunc copyfile;
@ -666,7 +701,7 @@ int copyin(Tcl_Interp *interp, hfsvol *vol, char *argv[])
copyfile = cpi_raw;
else
{
interp->result = "bad mode: must be macb, binh, text, or raw";
Tcl_SetResult(interp, "bad mode: must be macb, binh, text, or raw", TCL_STATIC);
return TCL_ERROR;
}
@ -684,7 +719,7 @@ int copyin(Tcl_Interp *interp, hfsvol *vol, char *argv[])
* DESCRIPTION: copy an HFS file out to a UNIX file
*/
static
int copyout(Tcl_Interp *interp, hfsvol *vol, char *argv[])
int copyout(Tcl_Interp *interp, hfsvol *vol, const char *argv[])
{
cpofunc copyfile;
@ -701,7 +736,7 @@ int copyout(Tcl_Interp *interp, hfsvol *vol, char *argv[])
copyfile = cpo_raw;
else
{
interp->result = "bad mode: must be macb, binh, text, or raw";
Tcl_SetResult(interp, "bad mode: must be macb, binh, text, or raw", TCL_STATIC);
return TCL_ERROR;
}
@ -807,7 +842,7 @@ void vol_del(ClientData clientData)
*/
static
int vol_cmd(ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
int argc, const char *argv[])
{
volref *vref = clientData;
hfsvol *vol = vref->vol;
@ -815,7 +850,7 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
switch (argc)
{
case 1:
interp->result = "missing command";
Tcl_SetResult(interp, "missing command", TCL_STATIC);
return TCL_ERROR;
case 2:
@ -831,21 +866,21 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
hfsvolent ent;
hfs_vstat(vol, &ent);
sprintf(interp->result, "%lu %lu", ent.totbytes, ent.freebytes);
resultf(interp, "%lu %lu", ent.totbytes, ent.freebytes);
}
else if (strcmp(argv[1], "crdate") == 0)
{
hfsvolent ent;
hfs_vstat(vol, &ent);
sprintf(interp->result, "%ld", (long) ent.crdate);
resultf(interp, "%ld", (long) ent.crdate);
}
else if (strcmp(argv[1], "mddate") == 0)
{
hfsvolent ent;
hfs_vstat(vol, &ent);
sprintf(interp->result, "%ld", (long) ent.mddate);
resultf(interp, "%ld", (long) ent.mddate);
}
else if (strcmp(argv[1], "islocked") == 0)
{
@ -853,9 +888,9 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
hfs_vstat(vol, &ent);
if (ent.flags & HFS_ISLOCKED)
interp->result = "1";
Tcl_SetResult(interp, "1", TCL_STATIC);
else
interp->result = "0";
Tcl_SetResult(interp, "0", TCL_STATIC);
}
else if (strcmp(argv[1], "umount") == 0)
{
@ -864,13 +899,13 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
return error(interp, 0);
}
else if (strcmp(argv[1], "cwd") == 0)
sprintf(interp->result, "%lu", vref->cwd);
resultf(interp, "%lu", vref->cwd);
else if (strcmp(argv[1], "path") == 0)
{
char name[HFS_MAX_FLEN + 1];
long id;
unsigned long id;
int listc, i;
char **listv;
const char **listv;
char *result;
id = vref->cwd;
@ -884,12 +919,12 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
/* reverse the resulting list */
if (Tcl_SplitList(interp, interp->result, &listc, &listv) != TCL_OK)
if (Tcl_SplitList(interp, Tcl_GetStringResult(interp), &listc, &listv) != TCL_OK)
return TCL_ERROR;
for (i = 0; i < listc / 2; ++i)
{
char *tmp;
const char *tmp;
tmp = listv[i];
listv[i] = listv[listc - 1 - i];
@ -897,7 +932,7 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
}
result = Tcl_Merge(listc, listv);
Tcl_Free(listv);
Tcl_Free((char*)listv);
Tcl_SetResult(interp, result, TCL_DYNAMIC);
}
@ -912,7 +947,7 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
return error(interp, 0);
}
else if (strcmp(argv[1], "sepchar") == 0)
interp->result = ":";
Tcl_SetResult(interp, ":", TCL_STATIC);
else
{
Tcl_AppendResult(interp, "bad command \"", argv[1],
@ -933,7 +968,7 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
}
else if (strcmp(argv[1], "dirinfo") == 0)
{
long id;
unsigned long id;
char name[HFS_MAX_FLEN + 1], idstr[CHARLEN(unsigned long) + 1];
if (Tcl_ExprLong(interp, argv[2], &id) != TCL_OK)
@ -959,7 +994,7 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
fref = ALLOC(fileref, 1);
if (fref == 0)
{
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -984,7 +1019,7 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
str = direntstr(&ent);
if (str == 0)
{
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -1024,7 +1059,8 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
else if (strcmp(argv[1], "glob") == 0)
{
int listc, fargc;
char **listv, **fargv, *result;
const char **listv;
char **fargv, *result;
if (hfs_setcwd(vol, vref->cwd) == -1)
return error(interp, 0);
@ -1033,16 +1069,16 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
return TCL_ERROR;
fargv = hfs_glob(vol, listc, listv, &fargc);
free(listv);
Tcl_Free((void*)listv);
if (fargv == 0)
{
interp->result = "globbing error";
Tcl_SetResult(interp, "globbing error", TCL_STATIC);
return TCL_ERROR;
}
result = Tcl_Merge(fargc, fargv);
Tcl_Free(fargv);
result = Tcl_Merge(fargc, (const char**)fargv);
free(fargv);
Tcl_SetResult(interp, result, TCL_DYNAMIC);
}
@ -1093,14 +1129,14 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
if (strlen(argv[3]) != 4 ||
strlen(argv[4]) != 4)
{
interp->result = "type and creator must be 4 character strings";
Tcl_SetResult(interp, "type and creator must be 4 character strings", TCL_STATIC);
return TCL_ERROR;
}
fref = ALLOC(fileref, 1);
if (fref == 0)
{
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -1152,13 +1188,13 @@ int vol_cmd(ClientData clientData, Tcl_Interp *interp,
*/
static
int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
int argc, const char *argv[])
{
static int id = 0;
if (argc < 2)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
@ -1173,7 +1209,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (argc < 3 || argc > 4)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
@ -1192,7 +1228,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (nparts > 1)
{
sprintf(interp->result, "must specify partition number "
resultf(interp, "must specify partition number "
"(%d available)", nparts);
return TCL_ERROR;
}
@ -1205,7 +1241,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
vref = ALLOC(volref, 1);
if (vref == 0)
{
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -1225,12 +1261,13 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
entry = Tcl_CreateHashEntry(&volumes, (char *) vref, &new);
char buf[sizeof("hfsvol") + sizeof(int) * 3];
do
sprintf(interp->result, "hfsvol%d", id++);
while (Tcl_GetCommandInfo(interp, interp->result, &info));
snprintf(buf, sizeof(buf), "hfsvol%d", id++);
while (Tcl_GetCommandInfo(interp, buf, &info));
Tcl_CreateCommand(interp, interp->result,
vol_cmd, vref, vol_del);
Tcl_CreateCommand(interp, buf, vol_cmd, vref, vol_del);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
}
else if (strcmp(argv[1], "zero") == 0)
{
@ -1239,7 +1276,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (argc != 4)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
@ -1249,7 +1286,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (do_zero(argv[2], nparts, &len) == -1)
return error(interp, 0);
sprintf(interp->result, "%lu", len);
resultf(interp, "%lu", len);
}
else if (strcmp(argv[1], "mkpart") == 0)
{
@ -1257,7 +1294,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (argc != 4)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
@ -1273,7 +1310,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (argc != 3)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
@ -1281,7 +1318,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
nparts = hfs_nparts(argv[2]);
suid_disable();
sprintf(interp->result, "%d", nparts);
resultf(interp, "%d", nparts);
}
else if (strcmp(argv[1], "format") == 0)
{
@ -1289,7 +1326,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (argc < 5 || argc > 6)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
@ -1299,7 +1336,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (argc == 6)
{
int listc, i;
char **listv;
const char **listv;
unsigned long *badblocks;
if (Tcl_SplitList(interp, argv[5], &listc, &listv) != TCL_OK)
@ -1308,9 +1345,9 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
badblocks = ALLOCX(unsigned long, listc);
if (listc && badblocks == 0)
{
Tcl_Free(listv);
Tcl_Free((void*)listv);
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -1319,13 +1356,13 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (Tcl_ExprLong(interp, listv[i],
(long *) &badblocks[i]) != TCL_OK)
{
Tcl_Free(listv);
Tcl_Free((void*)listv);
FREE(badblocks);
return TCL_ERROR;
}
}
Tcl_Free(listv);
Tcl_Free((void*)listv);
if (do_format(argv[2], partno, 0, argv[4], listc, badblocks) == -1)
{
@ -1351,7 +1388,7 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
if (argc != 5)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
@ -1360,8 +1397,8 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
(strcmp(argv[3], "latin1") != 0 &&
strcmp(argv[3], "macroman") != 0))
{
interp->result = "bad arg to chartrans: "
"charsets must be one of latin1, macroman";
Tcl_SetResult(interp, "bad arg to chartrans: "
"charsets must be one of latin1, macroman", TCL_STATIC);
return TCL_ERROR;
}
@ -1373,13 +1410,13 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
result = cs_latin1(argv[4], 0);
else
{
Tcl_SetResult(interp, argv[4], TCL_VOLATILE);
Tcl_SetObjResult(interp, Tcl_NewStringObj(argv[4], -1));
return TCL_OK;
}
if (result == 0)
{
interp->result = "out of memory";
Tcl_SetResult(interp, "out of memory", TCL_STATIC);
return TCL_ERROR;
}
@ -1393,41 +1430,41 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
{
if (argc != 2)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
interp->result = (char *) hfsutils_version;
Tcl_SetResult(interp, (char *)hfsutils_version, TCL_STATIC);
}
else if (strcmp(argv[1], "copyright") == 0)
{
if (argc != 2)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
interp->result = (char *) hfsutils_copyright;
Tcl_SetResult(interp, (char *)hfsutils_copyright, TCL_STATIC);
}
else if (strcmp(argv[1], "author") == 0)
{
if (argc != 2)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
interp->result = (char *) hfsutils_author;
Tcl_SetResult(interp, (char *)hfsutils_author, TCL_STATIC);
}
else if (strcmp(argv[1], "license") == 0)
{
if (argc != 2)
{
interp->result = "wrong # args";
Tcl_SetResult(interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
interp->result = (char *) hfsutils_license;
Tcl_SetResult(interp, (char *)hfsutils_license, TCL_STATIC);
}
else
{
@ -1448,13 +1485,13 @@ int cmd_hfs(ClientData clientData, Tcl_Interp *interp,
*/
static
int cmd_exit(ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
int argc, const char *argv[])
{
int status = 0;
if (argc > 2)
{
interp->result = "wrong # args: should be \"exit ?returnCode?\"";
Tcl_SetResult(interp, "wrong # args: should be \"exit ?returnCode?\"", TCL_STATIC);
return TCL_ERROR;
}
@ -1477,8 +1514,8 @@ int Hfs_Init(Tcl_Interp *interp)
Tcl_InitHashTable(&volumes, TCL_ONE_WORD_KEYS);
Tcl_InitHashTable(&files, TCL_ONE_WORD_KEYS);
Tcl_CreateCommand(interp, "hfs", cmd_hfs, 0, 0);
Tcl_CreateCommand(interp, "exit", cmd_exit, 0, 0);
Tcl_CreateCommand(interp, "hfs", cmd_hfs, NULL, NULL);
Tcl_CreateCommand(interp, "exit", cmd_exit, NULL, NULL);
return TCL_OK;
}