2007-07-23 13:04:48 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* 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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-07-23 13:04:48 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
2010-10-31 07:23:53 +00:00
|
|
|
#ifndef D_A2IO_H
|
|
|
|
#define D_A2IO_H
|
2007-07-23 13:04:48 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2008-07-05 15:37:02 +00:00
|
|
|
#include <cerrno>
|
2010-04-19 12:53:58 +00:00
|
|
|
#ifdef HAVE_POLL_H
|
|
|
|
# include <poll.h>
|
|
|
|
#endif // HAVE_POLL_H
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h>
|
|
|
|
#endif // HAVE_IO_H
|
2012-12-01 07:58:45 +00:00
|
|
|
#ifdef HAVE_WINIOCTL_H
|
|
|
|
# include <winioctl.h>
|
|
|
|
#endif // HAVE_WINIOCTL_H
|
|
|
|
#ifdef HAVE_SHARE_H
|
|
|
|
# include <share.h>
|
|
|
|
#endif // HAVE_SHARE_H
|
2007-07-23 13:04:48 +00:00
|
|
|
|
|
|
|
// in some platforms following definitions are missing:
|
|
|
|
#ifndef EINPROGRESS
|
|
|
|
# define EINPROGRESS (WSAEINPROGRESS)
|
|
|
|
#endif // EINPROGRESS
|
|
|
|
|
|
|
|
#ifndef O_NONBLOCK
|
|
|
|
# define O_NONBLOCK (O_NDELAY)
|
|
|
|
#endif // O_NONBLOCK
|
|
|
|
|
|
|
|
#ifndef O_BINARY
|
|
|
|
# define O_BINARY (0)
|
|
|
|
#endif // O_BINARY
|
|
|
|
|
|
|
|
// st_mode flags
|
|
|
|
#ifndef S_IRUSR
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IRUSR 0000400 /* read permission, owner */
|
|
|
|
#endif /* S_IRUSR */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IWUSR
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IWUSR 0000200 /* write permission, owner */
|
|
|
|
#endif /* S_IWUSR */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IXUSR
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IXUSR 0000100/* execute/search permission, owner */
|
2007-07-23 13:04:48 +00:00
|
|
|
#endif /* S_IXUSR */
|
|
|
|
#ifndef S_IRWXU
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
|
|
|
|
#endif /* S_IRWXU */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IRGRP
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IRGRP 0000040 /* read permission, group */
|
|
|
|
#endif /* S_IRGRP */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IWGRP
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IWGRP 0000020 /* write permission, grougroup */
|
|
|
|
#endif /* S_IWGRP */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IXGRP
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IXGRP 0000010/* execute/search permission, group */
|
2007-07-23 13:04:48 +00:00
|
|
|
#endif /* S_IXGRP */
|
|
|
|
#ifndef S_IRWXG
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
|
|
|
|
#endif /* S_IRWXG */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IROTH
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IROTH 0000004 /* read permission, other */
|
|
|
|
#endif /* S_IROTH */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IWOTH
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IWOTH 0000002 /* write permission, other */
|
|
|
|
#endif /* S_IWOTH */
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifndef S_IXOTH
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IXOTH 0000001/* execute/search permission, other */
|
2007-07-23 13:04:48 +00:00
|
|
|
#endif /* S_IXOTH */
|
|
|
|
#ifndef S_IRWXO
|
2010-01-05 16:01:46 +00:00
|
|
|
# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
|
|
|
|
#endif /* S_IRWXO */
|
2007-07-23 13:04:48 +00:00
|
|
|
|
2008-06-16 13:18:26 +00:00
|
|
|
// Use 'nul' instead of /dev/null in win32.
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifdef HAVE_WINSOCK2_H
|
|
|
|
# define DEV_NULL "nul"
|
|
|
|
#else
|
|
|
|
# define DEV_NULL "/dev/null"
|
|
|
|
#endif // HAVE_WINSOCK2_H
|
|
|
|
|
2009-12-09 14:32:12 +00:00
|
|
|
// Use 'con' instead of '/dev/stdin' and '/dev/stdout' in win32.
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifdef HAVE_WINSOCK2_H
|
2009-12-09 14:32:12 +00:00
|
|
|
# define DEV_STDIN "con"
|
2007-07-23 13:04:48 +00:00
|
|
|
# define DEV_STDOUT "con"
|
|
|
|
#else
|
2009-12-09 14:32:12 +00:00
|
|
|
# define DEV_STDIN "/dev/stdin"
|
2007-07-23 13:04:48 +00:00
|
|
|
# define DEV_STDOUT "/dev/stdout"
|
|
|
|
#endif // HAVE_WINSOCK2_H
|
|
|
|
|
|
|
|
#ifdef __MINGW32__
|
2010-01-24 13:49:07 +00:00
|
|
|
# define a2lseek(fd, offset, origin) _lseeki64(fd, offset, origin)
|
|
|
|
# define a2fseek(fd, offset, origin) _fseeki64(fd, offset, origin)
|
|
|
|
# define a2fstat(fd, buf) _fstati64(fd, buf)
|
|
|
|
# define a2ftell(fd) _ftelli64(fd)
|
|
|
|
# define a2wstat(path, buf) _wstati64(path, buf)
|
2008-06-16 13:18:26 +00:00
|
|
|
# ifdef stat
|
|
|
|
# undef stat
|
|
|
|
# endif // stat
|
2008-07-06 04:38:54 +00:00
|
|
|
# define a2_struct_stat struct _stati64
|
2011-08-04 12:43:02 +00:00
|
|
|
# define a2stat(path, buf) _wstati64(path, buf)
|
2010-01-24 13:49:07 +00:00
|
|
|
# define a2tell(handle) _telli64(handle)
|
2011-08-04 12:43:02 +00:00
|
|
|
# define a2mkdir(path, openMode) _wmkdir(path)
|
|
|
|
# define a2utimbuf _utimbuf
|
|
|
|
# define a2utime(path, times) _wutime(path, times)
|
|
|
|
# define a2unlink(path) _wunlink(path)
|
|
|
|
# define a2rmdir(path) _wrmdir(path)
|
|
|
|
# define a2rename(src, dest) _wrename(src, dest)
|
2012-12-01 07:58:45 +00:00
|
|
|
// For Windows, we share files for reading and writing.
|
|
|
|
# define a2open(path, flags, mode) _wsopen(path, flags, _SH_DENYNO, mode)
|
|
|
|
# define a2fopen(path, mode) _wfsopen(path, mode, _SH_DENYNO)
|
2010-01-24 13:49:07 +00:00
|
|
|
#else // !__MINGW32__
|
|
|
|
# define a2lseek(fd, offset, origin) lseek(fd, offset, origin)
|
|
|
|
# define a2fseek(fp, offset, origin) fseek(fp, offset, origin)
|
|
|
|
# define a2fstat(fp, buf) fstat(fp, buf)
|
|
|
|
# define a2ftell(fp) ftell(fp)
|
2008-07-06 04:38:54 +00:00
|
|
|
# define a2_struct_stat struct stat
|
2010-01-24 13:49:07 +00:00
|
|
|
# define a2stat(path, buf) stat(path, buf)
|
2007-07-23 13:04:48 +00:00
|
|
|
# define a2mkdir(path, openMode) mkdir(path, openMode)
|
2011-08-04 12:43:02 +00:00
|
|
|
# define a2utimbuf utimbuf
|
|
|
|
# define a2utime(path, times) ::utime(path, times)
|
|
|
|
# define a2unlink(path) unlink(path)
|
|
|
|
# define a2rmdir(path) rmdir(path)
|
|
|
|
# define a2rename(src, dest) rename(src, dest)
|
|
|
|
# define a2open(path, flags, mode) open(path, flags, mode)
|
2011-08-05 09:34:07 +00:00
|
|
|
# define a2fopen(path, mode) fopen(path, mode)
|
2010-01-24 13:49:07 +00:00
|
|
|
#endif // !__MINGW32__
|
2007-07-23 13:04:48 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
#define OPEN_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
|
|
|
|
#define DIR_OPEN_MODE S_IRWXU|S_IRWXG|S_IRWXO
|
|
|
|
|
2010-10-31 07:23:53 +00:00
|
|
|
#endif // D_A2IO_H
|