summaryrefslogtreecommitdiff
path: root/UGlibC_compat.pas
blob: 95cd75d5370eceb1f3f595a3fb2ee461b8212138 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
(*
    Tux Commander - UGlibC_compat - glibc compatibility for 32- and 64-bit platforms
    Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
    Check for updates on tuxcmd.sourceforge.net

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*)
unit UGlibC_compat;

interface
uses Classes, SysUtils {$IFNDEF CPU64}, Libc{$ENDIF};


const GLIBC_LIB = 'libc.so.6';

type
{$IFDEF KYLIX}
     QWORD = Int64;
{$ENDIF}

{$IFNDEF CPU64}
   TTimeT = DWORD;
{$ELSE}
   TTimeT = QWORD;
{$ENDIF}

   PGlibc_IOFile = pointer;

   TGlibc_timespec = packed record
{$IFNDEF CPU64}   //  32-bit platform
     tv_sec: longint;     //  Seconds.
     tv_nsec: longint;    //  Nanoseconds.
{$ELSE}           //  64-bit platform
     tv_sec: Int64;       //  Seconds.
     tv_nsec: Int64;      //  Nanoseconds.
{$ENDIF}
   end;

   PGlibc_stat = ^TGlibc_stat;
{$IFDEF KYLIX}
   TGlibc_stat = TStatBuf;
{$ELSE}
{$IFNDEF CPU64}   //  32-bit platform
   TGlibc_stat = packed record
        st_dev : __dev_t;
        __pad1 : word;
        __align_pad1 : word;
        st_ino : __ino_t;
        st_mode : __mode_t;
        st_nlink : __nlink_t;
        st_uid : __uid_t;
        st_gid : __gid_t;
        st_rdev : __dev_t;
        __pad2 : word;
        __align_pad2 : word;
        st_size : __off_t;
        st_blksize : __blksize_t;
        st_blocks : __blkcnt_t;

        st_atim : TGlibc_timespec;
        st_mtim : TGlibc_timespec;
        st_ctim : TGlibc_timespec;

{        st_atime : __time_t;
        __unused1 : dword;
        st_mtime : __time_t;
        __unused2 : dword;
        st_ctime : __time_t;
        __unused3 : dword; }

        __unused4 : dword;
        __unused5 : dword;
     end;
{$ELSE}           //  64-bit platform
   TGlibc_stat = packed record
        st_dev : QWORD;
        st_ino : Int64;
        st_nlink : QWORD;
        st_mode : DWORD;
        st_uid : DWORD;
        st_gid : DWORD;
        pad0 : DWORD;
        st_rdev : QWORD;
        st_size : Int64;
        st_blksize : Int64;
        st_blocks : Int64;
        st_atim : TGlibc_timespec;
        st_mtim : TGlibc_timespec;
        st_ctim : TGlibc_timespec;
        __unused : array[1..3] of QWORD;
     end;
{$ENDIF}
{$ENDIF}

   PGlibc_stat64 = ^TGlibc_stat64;
{$IFDEF KYLIX}
   TGlibc_stat64 = TStatBuf64;
{$ELSE}
   TGlibc_stat64 = packed record
{$IFNDEF CPU64}   //  32-bit platform
        st_dev : __dev_t;
        __pad1 : dword;
        __st_ino : __ino_t;
        st_mode : __mode_t;
        st_nlink : __nlink_t;
        st_uid : __uid_t;
        st_gid : __gid_t;
        st_rdev : __dev_t;
        __pad2 : dword;
        st_size : __off64_t;
        st_blksize : __blksize_t;
        st_blocks : __blkcnt64_t;

        st_atim : TGlibc_timespec;
        st_mtim : TGlibc_timespec;
        st_ctim : TGlibc_timespec;

{        st_atime : __time_t;
        __unused1 : dword;
        st_mtime : __time_t;
        __unused2 : dword;
        st_ctime : __time_t;
        __unused3 : dword; }

        st_ino : __ino64_t;
{$ELSE}           //  64-bit platform
        st_dev : QWORD;
        st_ino : Int64;
        st_nlink : QWORD;
        st_mode : DWORD;
        st_uid : DWORD;
        st_gid : DWORD;
        pad0 : DWORD;
        st_rdev : QWORD;
        st_size : Int64;
        st_blksize : Int64;
        st_blocks : Int64;
        st_atim : TGlibc_timespec;
        st_mtim : TGlibc_timespec;
        st_ctim : TGlibc_timespec;
        __unused : array[1..3] of QWORD;
{$ENDIF}
     end;
{$ENDIF}


   TGlibc_fsid_t = packed record
     __val : array[0..1] of longint;
   end;

   PGlibc_statfs64 = ^TGlibc_statfs64;
   TGlibc_statfs64 = packed record
{$IFNDEF CPU64}   //  32-bit platform
        f_type : longint;
        f_bsize : longint;
        f_blocks : __fsblkcnt64_t;
        f_bfree : __fsblkcnt64_t;
        f_bavail : __fsblkcnt64_t;
        f_files : __fsfilcnt64_t;
        f_ffree : __fsfilcnt64_t;
        f_fsid : __fsid_t;
        f_namelen : longint;
        f_spare : array[0..5] of longint;
{$ELSE}           //  64-bit platform
        f_type : Int64;
        f_bsize : Int64;
        f_blocks : QWORD;
        f_bfree : QWORD;
        f_bavail : QWORD;
        f_files : QWORD;
        f_ffree : QWORD;
        f_fsid : TGlibc_fsid_t;
        f_namelen : Int64;
        f_spare : array[0..5] of Int64;
{$ENDIF}
     end;

   PGlibc_utimbuf = ^TGlibc_utimbuf;
   TGlibc_utimbuf = packed record
{$IFNDEF CPU64}   //  32-bit platform
        actime : __time_t;
        modtime : __time_t;
{$ELSE}           //  64-bit platform
        actime : Int64;
        modtime : Int64;
{$ENDIF}
   end;
   
   PGlibc_mntent = ^TGlibc_mntent;
   TGlibc_mntent = packed record
{$IFNDEF CPU64}   //  32-bit platform
        mnt_fsname : Pchar;
        mnt_dir : Pchar;
        mnt_type : Pchar;
        mnt_opts : Pchar;
        mnt_freq : longint;
        mnt_passno : longint;
{$ELSE}           //  64-bit platform
        mnt_fsname : Pchar;
        mnt_dir : Pchar;
        mnt_type : Pchar;
        mnt_opts : Pchar;
        mnt_freq : Longint;
        mnt_passno : Longint;
{$ENDIF}
     end;





{$IFNDEF KYLIX}
function glibc_stat64(const afile: PChar; buf: PGlibc_stat64): longint; cdecl; external GLIBC_LIB name 'stat64';
function glibc_lstat64(const path: PChar; buf: PGlibc_stat64): longint; cdecl; external GLIBC_LIB name 'lstat64';
{$ELSE}
function glibc_stat64(const afile: PChar; buf: PGlibc_stat64): longint;
function glibc_lstat64(const path: PChar; buf: PGlibc_stat64): longint;
{$ENDIF}

{
function glibc_localtime(timep: Pointer): Pointer; cdecl; external GLIBC_LIB name 'localtime';
function glibc_strftime(s: PChar; max: Longint; format: PChar; tm: Pointer): Longint; cdecl; external GLIBC_LIB name 'strftime';
}

function glibc_statfs64(const path: PChar; buf: PGlibc_statfs64): longint; cdecl; external GLIBC_LIB name 'statfs64';

function glibc_fileno(stream: PGlibc_IOFile): integer; cdecl; external GLIBC_LIB name 'fileno';

function glibc_utime(const afile: Pchar; buf: PGlibc_utimbuf): Longint; cdecl; external GLIBC_LIB name 'utime';


function glibc_setmntent(const afile: Pchar; mode: Pchar): PGlibc_IOFile; cdecl; external GLIBC_LIB name 'setmntent';
function glibc_getmntent(stream: PGlibc_IOFile): PGlibc_mntent; cdecl; external GLIBC_LIB name 'getmntent';
function glibc_endmntent(stream: PGlibc_IOFile): Longint; cdecl; external GLIBC_LIB name 'endmntent';


implementation

{$IFDEF KYLIX}
function glibc__xstat64(ver: integer; const afile: PChar; buf: PGlibc_stat64): longint; cdecl; external GLIBC_LIB name '__xstat64';
function glibc__lxstat64(ver: integer; const path: PChar; buf: PGlibc_stat64): longint; cdecl; external GLIBC_LIB name '__lxstat64';

function glibc_stat64(const afile: PChar; buf: PGlibc_stat64): longint;
begin
  Result := glibc__xstat64(_STAT_VER, afile, buf);
end;

function glibc_lstat64(const path: PChar; buf: PGlibc_stat64): longint;
begin
  Result := glibc__lxstat64(_STAT_VER, path, buf);
end;
{$ENDIF}

end.