summaryrefslogtreecommitdiff
path: root/Build/source/texk/cjkutils/cjkutils-4.8.4/hbf2gf/emdir.c
blob: 4e759c83eb28b7c393529c139ae07989670c8a9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* emdir.c  -- Written by Eberhard Mattes, donated to the public domain */

#include "emdir.h"

#ifdef OS2

#undef HPS
#define INCL_DOSFILEMGR
#include <os2.h>
#include <string.h>

#define FHDIR(b) (*(HDIR *)(b)->reserved)

static void fconv (struct ll_findbuffer *dst, const FILEFINDBUF *src)
{
  dst->attr = src->attrFile;
  dst->time = *(unsigned *)&src->ftimeLastWrite;
  dst->date = *(unsigned *)&src->fdateLastWrite;
  dst->size = src->cbFile;
  strcpy (dst->name, src->achName);
}


int ll_findfirst (const char *path, int attr, struct ll_findbuffer *buffer)
{
  USHORT rc;
  ULONG count;
  HDIR hdir;
  FILEFINDBUF ffbuf;

  hdir = HDIR_CREATE;
  count = 1;
  rc = DosFindFirst ((PSZ)path, &hdir, attr, &ffbuf, sizeof (ffbuf),
		     &count, 0L);
  if (rc != 0 || count != 1)
    return 0;
  FHDIR (buffer) = hdir;
  fconv (buffer, &ffbuf);
  return 1;
}


int ll_findnext (struct ll_findbuffer *buffer)
{
  USHORT rc;
  ULONG count;
  HDIR hdir;
  FILEFINDBUF ffbuf;

  hdir = FHDIR (buffer);
  count = 1;
  rc = DosFindNext (hdir, &ffbuf, sizeof (ffbuf), &count);
  if (rc != 0 || count != 1)
    {
      DosFindClose (hdir);
      return 0;
    }
  fconv (buffer, &ffbuf);
  return 1;
}


#elif defined(DJGPP)

/* djgpp support by Hartmut Schirmer (hsc@techfak.uni-kiel.de), May 30, 1997 */

#include <dos.h>
#include <dir.h>

static int ll_attr = 0;
int ll_findnext (struct ll_findbuffer *buffer)
{
  int res;
  do {
    res = _dos_findnext ((struct find_t *)buffer);
    if (res != 0) return 0;
  } while ( (buffer->attrib&ll_attr) == 0);
  return 1;
}

int ll_findfirst (const char *path, int attr, struct ll_findbuffer *buffer)
{
  int res;
  ll_attr = attr;
  res = _dos_findfirst((char *)path, attr, (struct find_t *)buffer);
  if (res != 0) return 0;
  if ( (buffer->attrib&ll_attr) == 0)
    return ll_findnext(buffer);
  return 1;
}

#elif !defined(__EMX__)   /* if not OS2 nor DJGPP nor __EMX__ defined */

/* Not tested */

#include <dos.h>

int ll_findfirst (const char *path, int attr, struct ll_findbuffer *buffer)
{
  return _dos_findfirst (path, attr, (struct find_t *)buffer) == 0;
}


int ll_findnext (struct ll_findbuffer *buffer)
{
  return _dos_findnext ((struct find_t *)buffer) == 0;
}

#endif