source: trunk/src/kash/shfile.h@ 2303

Last change on this file since 2303 was 2303, checked in by bird, 16 years ago

kash: new execve implementation for windows. more file ops.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1/* $Id: shfile.h 2303 2009-03-01 07:25:29Z bird $ */
2/** @file
3 *
4 * File management.
5 *
6 * Copyright (c) 2007-2009 knut st. osmundsen <bird-kBuild-spamix@anduin.net>
7 *
8 *
9 * This file is part of kBuild.
10 *
11 * kBuild is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * kBuild is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with kBuild; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef ___shfile_h
28#define ___shfile_h
29
30#include "shtypes.h"
31#include "shthread.h"
32#include <fcntl.h>
33#include <sys/stat.h>
34#ifdef _MSC_VER
35# define _PATH_DEVNULL "nul"
36# define _PATH_DEFPATH "."
37#else
38# if !defined(__sun__)
39# include <paths.h>
40# endif
41# ifdef _PATH_DEVNULL
42# define _PATH_DEVNULL "/dev/null"
43# endif
44# ifndef _PATH_DEFPATH
45# define _PATH_DEFPATH "/bin:/usr/bin:/sbin:/usr/sbin"
46# endif
47#endif
48#ifndef _MSC_VER
49# include <sys/fcntl.h>
50# include <unistd.h>
51# ifndef O_BINARY
52# define O_BINARY 0
53# endif
54# ifndef O_TEXT
55# define O_TEXT 0
56# endif
57
58#else
59# include <io.h>
60# include <direct.h>
61
62# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
63# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
64# define S_ISLNK(m) 0
65# define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
66# define S_IXUSR _S_IEXEC
67# define S_IWUSR _S_IWRITE
68# define S_IRUSR _S_IREAD
69# define S_IRWXG 0000070
70# define S_IRGRP 0000040
71# define S_IWGRP 0000020
72# define S_IXGRP 0000010
73# define S_IRWXO 0000007
74# define S_IROTH 0000004
75# define S_IWOTH 0000002
76# define S_IXOTH 0000001
77# define S_ISUID 0004000
78# define S_ISGID 0002000
79# define ALLPERMS 0000777
80
81# define F_DUPFD 0
82# define F_GETFD 1
83# define F_SETFD 2
84# define F_GETFL 3
85# define F_SETFL 4
86# define FD_CLOEXEC 1
87
88# define F_OK 0
89# define X_OK 1
90# define W_OK 2
91# define R_OK 4
92
93# define O_NONBLOCK 0 /** @todo */
94
95#endif
96
97
98/**
99 * One file.
100 */
101typedef struct shfile
102{
103 int fd; /**< The shell file descriptor number. */
104 int flags; /**< Open flags. */
105 unsigned cloexec : 1; /**< Close on exec flag. */
106 intptr_t native; /**< The native file descriptor number. */
107} shfile;
108
109/**
110 * The file descriptor table for a shell.
111 */
112typedef struct shfdtab
113{
114 shmtx mtx; /**< Mutex protecting any operations on the table and it's handles. */
115 char *cwd; /**< The current directory for this shell instance. */
116 unsigned size; /**< The size of the table (number of entries). */
117 shfile *tab; /**< Pointer to the table. */
118} shfdtab;
119
120int shfile_init(shfdtab *, shfdtab *);
121void shfile_fork_win(shfdtab *pfdtab, int set, intptr_t *hndls);
122void *shfile_exec_win(shfdtab *pfdtab, int prepare, unsigned short *sizep, intptr_t *hndls);
123
124int shfile_open(shfdtab *, const char *, unsigned, mode_t);
125int shfile_pipe(shfdtab *, int [2]);
126int shfile_close(shfdtab *, unsigned);
127long shfile_read(shfdtab *, int, void *, size_t);
128long shfile_write(shfdtab *, int, const void *, size_t);
129long shfile_lseek(shfdtab *, int, long, int);
130int shfile_fcntl(shfdtab *, int fd, int cmd, int arg);
131int shfile_dup(shfdtab *, int fd);
132
133int shfile_stat(shfdtab *, const char *, struct stat *);
134int shfile_lstat(shfdtab *, const char *, struct stat *);
135int shfile_chdir(shfdtab *, const char *);
136char *shfile_getcwd(shfdtab *, char *, int);
137int shfile_access(shfdtab *, const char *, int);
138int shfile_isatty(shfdtab *, int);
139int shfile_cloexec(shfdtab *, int, int);
140int shfile_ioctl(shfdtab *, int, unsigned long, void *);
141#ifdef _MSC_VER
142# define TIOCGWINSZ 0x4201
143typedef struct sh_winsize
144{
145 unsigned ws_row; /**< Rows, in characters. */
146 unsigned ws_col; /**< Columns, in characters. */
147 unsigned ws_xpixel; /**< Horizontal size, pixels. */
148 unsigned ws_ypixel; /**< Vertical size, pixels. */
149} sh_winsize;
150#else
151typedef struct winsize sh_winsize;
152#endif
153mode_t shfile_get_umask(shfdtab *);
154void shfile_set_umask(shfdtab *, mode_t);
155
156
157typedef struct sh_dirent
158{
159 char name[260];
160} shdirent;
161
162typedef struct shdir
163{
164 shfdtab *shfdtab;
165 void *native;
166 shdirent ent;
167} shdir;
168
169shdir *shfile_opendir(shfdtab *, const char *);
170shdirent *shfile_readdir(struct shdir *);
171void shfile_closedir(struct shdir *);
172
173#endif
174
Note: See TracBrowser for help on using the repository browser.