MCPcopy Create free account
hub / github.com/NetHack/NetHack / docompress_file

Function docompress_file

src/files.c:1590–1775  ·  view source on GitHub ↗

* using system() is simpler, but opens up security holes and causes * problems on at least Interactive UNIX 3.0.1 (SVR3.2), where any * setuid is renounced by /bin/sh, so the files cannot be accessed. * * cf. child() in unixunix.c. */

Source from the content-addressed store, hash-verified

1588 * cf. child() in unixunix.c.
1589 */
1590staticfn void
1591docompress_file(const char *filename, boolean uncomp)
1592{
1593 char *cfn = 0;
1594 const char *xtra;
1595 FILE *cf;
1596 const char *args[10];
1597#ifdef COMPRESS_OPTIONS
1598 char opts[sizeof COMPRESS_OPTIONS];
1599#endif
1600 int i = 0;
1601 int f, childstatus;
1602 unsigned ln;
1603#ifdef TTY_GRAPHICS
1604 boolean istty = WINDOWPORT(tty);
1605#endif
1606
1607#ifdef COMPRESS_EXTENSION
1608 xtra = COMPRESS_EXTENSION;
1609#else
1610 xtra = "";
1611#endif
1612#ifdef SFCTOOL
1613 ln = strlen(filename) + sizeof COMPRESS_EXTENSION;
1614 cfn = (char *) alloc(ln);
1615#else /* SFCTOOL */
1616 ln = (unsigned) (strlen(filename) + strlen(xtra));
1617 cfn = (char *) alloc(ln + 1);
1618#endif /* SFCTOOL */
1619
1620 Strcpy(cfn, filename);
1621 Strcat(cfn, xtra);
1622
1623 /* when compressing, we know the file exists */
1624 if (uncomp) {
1625 if ((cf = fopen(cfn, RDBMODE)) == (FILE *) 0) {
1626 free((genericptr_t) cfn);
1627 return;
1628 }
1629 (void) fclose(cf);
1630 }
1631
1632 args[0] = COMPRESS;
1633 if (uncomp)
1634 args[++i] = "-d"; /* uncompress */
1635#ifdef COMPRESS_OPTIONS
1636 {
1637 /* we can't guarantee there's only one additional option, sigh */
1638 char *opt;
1639 boolean inword = FALSE;
1640
1641 opt = strcpy(opts, COMPRESS_OPTIONS);
1642 while (*opt) {
1643 if ((*opt == ' ') || (*opt == '\t')) {
1644 if (inword) {
1645 *opt = '\0';
1646 inword = FALSE;
1647 }

Callers 2

nh_compressFunction · 0.85
nh_uncompressFunction · 0.85

Calls 15

fcloseFunction · 0.85
raw_printFunction · 0.85
redirectFunction · 0.85
getuidFunction · 0.85
fprintfFunction · 0.85
unlinkFunction · 0.85
make_compressed_nameFunction · 0.85
freadFunction · 0.85
fwriteFunction · 0.85
allocFunction · 0.70
nh_terminateFunction · 0.70
plineFunction · 0.70

Tested by

no test coverage detected