fixed useragent
[syren.git] / src / sylib / syren_os.c
bloba3d5338aa30818138eeba83b207afa6c4cbd3f97
1 /*
2 Syren -- a lightweight downloader for Linux/BSD/MacOSX
3 inspired by Axel Copyright 2001-2002 Wilmer van der Gaast
4 version 0.0.6 (atomic alien)
5 coded by Ketmar // Vampire Avalon
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License with
18 the Debian GNU/Linux distribution in file /usr/doc/copyright/GPL;
19 if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 Suite 330, Boston, MA 02111-1307 USA
23 Syren os-specific functions
25 #ifndef _SYREN_OS_C
26 #define _SYREN_OS_C
28 #include "syren_os.h"
32 double SyGetTimeD (void) {
33 struct timeval time;
34 gettimeofday(&time, 0);
35 return ((double)time.tv_sec+(double)time.tv_usec/1000000);
39 #ifdef SY_INCLUDE_FILE_IO
40 TSyResult SyDeleteFile (const char *fname) {
41 if (!unlink(fname)) return SY_OK;
42 return SY_ERROR;
46 int SyOpenFile (const char *fname, TSyFileMode mode, TSyBool mustCreate) {
47 int mm = (mode==SY_FMODE_WRITE)?O_WRONLY:O_RDONLY;
49 if (mustCreate != SY_FALSE) mm = mm | O_CREAT;
50 return open(fname, mm, SY_FILE_DEFMODE);
54 TSyResult SyWriteFile (int fd, const void *buf, int count) {
55 int wr = write(fd, buf, count);
56 if (wr != count) return SY_ERROR;
57 return SY_OK;
61 TSyResult SyReadFile (int fd, void *buf, int count) {
62 int rd = read(fd, buf, count);
63 if (rd != count) return SY_ERROR;
64 return SY_OK;
68 TSyResult SySeekFile (int fd, int64_t offset) {
69 //!!
70 offset = offset<0?SY_LSEEK(fd, offset, SEEK_END):SY_LSEEK(fd, offset, SEEK_SET);
71 if (offset < 0) return SY_ERROR;
72 return SY_OK;
76 int64_t SyFileSize (int fd) {
77 int64_t size;
78 int64_t ppos = SY_LSEEK(fd, 0, SEEK_CUR);
79 if (ppos < 0) return -1;
80 size = SY_LSEEK(fd, 0, SEEK_END);
81 if (SY_LSEEK(fd, ppos, SEEK_SET) < 0) return -1;
82 return size;
84 #endif
87 TSyResult SySocketInit (void) {
88 return SY_OK;
91 void SySocketShutdown (void) {
95 #endif