1/*
2  Copyright (c) 1990-2005 Info-ZIP.  All rights reserved.
3
4  See the accompanying file LICENSE, version 2005-Feb-10 or later
5  (the contents of which are also included in zip.h) for terms of use.
6  If, for some reason, all these files are missing, the Info-ZIP license
7  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
8*/
9/* OS specific routines for AMIGA platform.
10 *
11 * John Bush    <John.Bush@east.sun.com>  BIX: jbush
12 * Paul Kienitz <kie@pacbell.net>
13 *
14 * History:
15 *
16 * Date     DoBee    Comments
17 * -------  -------- -----------------------------------------------
18 * 21Jan93  JBush    Original coding.
19 *                   Incorporated filedate.c (existing routine).
20 *
21 * 31Jan93  JBush    Made filedate.c include unconditional.
22 *
23 * 18Jul93  PaulK    Moved Aztec _abort() here from stat.c because we
24 *                   can't share the same one between Zip and UnZip.
25 *                   Added close_leftover_open_dirs() call to it.
26 *
27 * 17Apr95  PaulK    Added Amiga internal version string so that
28 *                   installer programs can compare the version being
29 *                   installed to see if the copy the user already has
30 *                   is older or newer.  Added Prestart_Hook to support
31 *                   debug tracing in deflate.a.
32 *
33 *  6May95  PaulK    Added GetComment() for filenote support.
34 *
35 * 12Nov95  PaulK    Added #define ZIP in front of filedate.c, for
36 *                   new options in there; removed declare of set_con()
37 *                   since echon() no longer expands to it (or anything).
38 *
39 * 12Feb96  PaulK    Removed call of echon() entirely.
40 *
41 * 12Jul97  PaulK    Made both Aztec and SAS define USE_TIME_LIB for filedate.c
42 *
43 * 26Aug97  PaulK    Added ClearIOErr_exit()
44 *
45 *  2Jan98  HWalt    Adapted for SAS/C using stat.c replacement functions
46 *
47 *  6Jun00  PaulK    Removed references to time_lib, since new filedate.c
48 *                   supercedes it
49 */
50
51#include <exec/memory.h>
52#ifdef AZTEC_C
53#  include <libraries/dos.h>
54#  include <libraries/dosextens.h>
55#  include <clib/exec_protos.h>
56#  include <clib/dos_protos.h>
57#  include <pragmas/exec_lib.h>
58#  include <pragmas/dos_lib.h>
59#else
60#  include <proto/exec.h>
61#  include <proto/dos.h>
62#endif
63#include <stdlib.h>
64#include "ziperr.h"
65void ziperr(int c, const char *h);
66
67#define ZIP
68#if !defined(UTIL)
69#  define NO_MKTIME
70#endif
71
72#ifdef AZTEC_C
73
74/* ============================================================= */
75/* filedate.c is an external file, since it's shared with UnZip. */
76/* Aztec includes it here, but SAS/C now compiles it separately. */
77#  include "amiga/filedate.c"
78
79/* the same applies to stat.c                                    */
80#  include "amiga/stat.c"
81
82#  define setenv BOGUS_INCOMPATIBLE_setenv
83#  include <fcntl.h>
84#  undef setenv
85#  ifdef DEBUG
86#    define PRESTART_HOOK
87#  endif
88#endif
89
90extern void close_leftover_open_dirs(void);
91
92
93/* the following handles cleanup when a ^C interrupt happens: */
94
95void _abort(void)               /* called when ^C is pressed */
96{
97    close_leftover_open_dirs();
98    ziperr(ZE_ABORT, "^C");
99}
100
101void ClearIOErr_exit(int e)     /* EXIT is defined as this */
102{
103    if (!e)
104        ((struct Process *) FindTask(NULL))->pr_Result2 = 0;
105    /* we clear IoErr() since we are successful, in a 1.x-compatible way */
106    exit(e);
107}
108
109
110/* Make sure the version number here matches the number in revision.h */
111/* as closely as possible in strict decimal "#.#" form:               */
112const char version_id[] = "\0$VER: Zip 2.3 ("
113#  include "env:VersionDate"
114")\r\n";
115
116/* call this with an arg of NULL to free storage: */
117
118char *GetComment(char *filename)
119{
120    BPTR lk;
121    static struct FileInfoBlock *fib = NULL;
122
123    if (!filename) {
124        if (fib) FreeMem(fib, sizeof(*fib));
125        fib = NULL;
126        return NULL;
127    }
128    if (!fib) {
129        if (!(fib = AllocMem(sizeof(*fib), MEMF_PUBLIC)))
130            ziperr(ZE_MEM, "was checking filenotes");
131    }
132    if (!(lk = Lock(filename, ACCESS_READ)))
133        return NULL;
134    if (!Examine(lk, fib))
135        fib->fib_Comment[0] = '\0';
136    UnLock(lk);
137    return fib->fib_Comment[0] ? &fib->fib_Comment[0] : NULL;
138}
139