1 /* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA */
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "../../utils/lib/os_stubs.h"
25 /*******************************************************************
31 *******************************************************************/
33 OFF_T
os_lseek(OS_FD fd
, OFF_T pos
, int dir
)
35 OFF_T result
= lseek(fd
, pos
, dir
);
37 if(result
< 0) unix_error(errno
, "os_lseek", Nothing
);
42 /*******************************************************************
48 *******************************************************************/
50 ssize_t
os_read(OS_FD fd
, char *buf
, size_t len
)
52 ssize_t result
= read(fd
, buf
, len
);
54 if(result
< 0) unix_error(errno
, "os_read", Nothing
);
59 /*******************************************************************
65 *******************************************************************/
67 /* TODO: write whole file if sparse disabled */
68 void os_ftruncate(OS_FD fd
, OFF_T len
, /* bool */ int sparse
)
71 if(!fd
) failwith("ftruncate32: file is closed");
73 cursize
= os_getfdsize(fd
);
76 OFF_T result
= lseek(fd
, len
-1, SEEK_SET
);
77 if(result
< 0) unix_error(errno
, "os_ftruncate", Nothing
);
81 if((cursize
!= len
) && (ftruncate(fd
, len
) < 0)) {
82 fprintf(stderr
, "ftruncate(%d,%Ld)\n", fd
, len
);
83 uerror("ml_truncate32: error in ftruncate",Nothing
);
87 /*******************************************************************
93 *******************************************************************/
95 int os_getdtablesize()
97 return getdtablesize();
100 /*******************************************************************
106 *******************************************************************/
108 int64
os_getfdsize(OS_FD fd
)
112 if(fstat(fd
, &buf
) < 0)
113 uerror("fstat: error in fstat",Nothing
);
118 /*******************************************************************
124 *******************************************************************/
126 int64
os_getfilesize(char *path
)
130 if(stat(path
, &buf
) < 0)
131 uerror("fstat: error in fstat",Nothing
);
136 /*******************************************************************
142 *******************************************************************/
144 void os_set_nonblock(OS_SOCKET fd
)
149 /*******************************************************************
155 *******************************************************************/
157 value
glibc_version(void)
162 #ifdef HAVE_GNU_LIBC_VERSION_H
163 #include <gnu/libc-version.h>
165 v
= copy_string (gnu_get_libc_version());
170 raise_constant(*(value
*)caml_named_value("not supported"));
175 /*******************************************************************
181 *******************************************************************/
183 #ifdef HAVE_SYS_UTSNAME_H
184 #include <sys/utsname.h>
186 void os_uname(char buf
[])
190 sprintf(buf
, "%s %s %s %s %s",
191 uts
.sysname
, uts
.nodename
, uts
.release
, uts
.version
, uts
.machine
);
196 void os_uname(char buf
[])
198 /* Do nothing to buf */
203 /*******************************************************************
209 *******************************************************************/
211 int os_os_supported()
213 return 1; /* return always 1 to expect an supported os */