2 * hosted io support for GDB's remote fileio protocol
4 * Copyright (c) 2006 CodeSourcery Inc
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
23 __hosted_to_gdb_mode_t (mode_t m
)
25 gdb_mode_t result
= 0;
27 result
|= GDB_S_IFREG
;
29 result
|= GDB_S_IFDIR
;
31 result
|= GDB_S_IRUSR
;
33 result
|= GDB_S_IWUSR
;
35 result
|= GDB_S_IXUSR
;
37 result
|= GDB_S_IRGRP
;
39 result
|= GDB_S_IWGRP
;
41 result
|= GDB_S_IXGRP
;
43 result
|= GDB_S_IROTH
;
45 result
|= GDB_S_IWOTH
;
47 result
|= GDB_S_IXOTH
;
52 __hosted_to_gdb_open_flags (int f
)
56 result
|= GDB_O_RDONLY
;
58 result
|= GDB_O_WRONLY
;
62 result
|= GDB_O_APPEND
;
64 result
|= GDB_O_CREAT
;
66 result
|= GDB_O_TRUNC
;
73 __hosted_to_gdb_lseek_flags (int f
)
77 else if (f
== SEEK_END
)
84 __hosted_from_gdb_stat (const struct gdb_stat
*gs
,
87 s
->st_dev
= gs
->st_dev
;
88 s
->st_ino
= gs
->st_ino
;
89 s
->st_mode
= gs
->st_mode
;
90 s
->st_nlink
= gs
->st_nlink
;
91 s
->st_uid
= gs
->st_uid
;
92 s
->st_gid
= gs
->st_gid
;
93 s
->st_rdev
= gs
->st_rdev
;
94 s
->st_size
= gs
->st_size
;
95 s
->st_blksize
= gs
->st_blksize
;
96 s
->st_blocks
= gs
->st_blocks
;
97 s
->st_atime
= gs
->st_atim
;
98 s
->st_mtime
= gs
->st_mtim
;
99 s
->st_ctime
= gs
->st_ctim
;
103 __hosted_from_gdb_timeval (const struct gdb_timeval
*gt
,
106 t
->tv_sec
= gt
->tv_sec
;
107 t
->tv_usec
= gt
->tv_usec
;
111 __hosted_from_gdb_errno (int32_t err
)
116 case GDB_EPERM
: return EPERM
;
117 case GDB_ENOENT
: return ENOENT
;
118 case GDB_EINTR
: return EINTR
;
119 case GDB_EBADF
: return EBADF
;
120 case GDB_EACCES
: return EACCES
;
121 case GDB_EFAULT
: return EFAULT
;
122 case GDB_EBUSY
: return EBUSY
;
123 case GDB_EEXIST
: return EEXIST
;
124 case GDB_ENODEV
: return ENODEV
;
125 case GDB_ENOTDIR
: return ENOTDIR
;
126 case GDB_EISDIR
: return EISDIR
;
127 case GDB_EINVAL
: return EINVAL
;
128 case GDB_ENFILE
: return ENFILE
;
129 case GDB_EMFILE
: return EMFILE
;
130 case GDB_EFBIG
: return EFBIG
;
131 case GDB_ENOSPC
: return ENOSPC
;
132 case GDB_ESPIPE
: return ESPIPE
;
133 case GDB_EROFS
: return EROFS
;
134 case GDB_ENAMETOOLONG
: return ENAMETOOLONG
;