VirtualBox

source: kBuild/trunk/src/kash/shfile.h@ 1784

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

kash: hacking.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1/* $Id: shfile.h 1784 2008-09-13 03:27:59Z bird $ */
2/** @file
3 *
4 * File management.
5 *
6 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
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 intptr_t native; /**< The native file descriptor number. */
106} shfile;
107
108/**
109 * The file descriptor table for a shell.
110 */
111typedef struct shfdtab
112{
113 shmtx mtx; /**< Mutex protecting any operations on the table and it's handles. */
114 char *cwd; /**< The current directory for this shell instance. */
115 unsigned size; /**< The size of the table (number of entries). */
116 shfile *tab; /**< Pointer to the table. */
117} shfdtab;
118
119int shfile_open(shfdtab *, const char *, unsigned, mode_t);
120int shfile_pipe(shfdtab *, int [2]);
121int shfile_close(shfdtab *, unsigned);
122long shfile_read(shfdtab *, int, void *, size_t);
123long shfile_write(shfdtab *, int, const void *, size_t);
124long shfile_lseek(shfdtab *, int, long, int);
125int shfile_fcntl(shfdtab *, int fd, int cmd, int arg);
126int shfile_dup(shfdtab *, int fd);
127
128int shfile_stat(shfdtab *, const char *, struct stat *);
129int shfile_lstat(shfdtab *, const char *, struct stat *);
130int shfile_chdir(shfdtab *, const char *);
131char *shfile_getcwd(shfdtab *, char *, int);
132int shfile_access(shfdtab *, const char *, int);
133int shfile_isatty(shfdtab *, int);
134int shfile_cloexec(shfdtab *, int, int);
135int shfile_ioctl(shfdtab *, int, unsigned long, void *);
136#ifdef _MSC_VER
137# define TIOCGWINSZ 0x4201
138typedef struct sh_winsize
139{
140 unsigned ws_row; /**< Rows, in characters. */
141 unsigned ws_col; /**< Columns, in characters. */
142 unsigned ws_xpixel; /**< Horizontal size, pixels. */
143 unsigned ws_ypixel; /**< Vertical size, pixels. */
144} sh_winsize;
145#else
146typedef struct winsize sh_winsize;
147#endif
148mode_t shfile_get_umask(shfdtab *);
149
150
151typedef struct sh_dirent
152{
153 char name[260];
154} shdirent;
155
156typedef struct shdir
157{
158 shfdtab *shfdtab;
159 void *native;
160 shdirent ent;
161} shdir;
162
163shdir *shfile_opendir(shfdtab *, const char *);
164shdirent *shfile_readdir(struct shdir *);
165void shfile_closedir(struct shdir *);
166
167#endif
168
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette