30 #include "filenames.h" 36 #include <sys/cygwin.h> 45 #define FIO_FD_INVALID -1 46 #define FIO_FD_CONSOLE_IN -2 47 #define FIO_FD_CONSOLE_OUT -3 63 for (i = 3; i < 10; ++i)
127 if (
flags & FILEIO_O_CREAT)
129 if (
flags & FILEIO_O_EXCL)
131 if (
flags & FILEIO_O_TRUNC)
133 if (
flags & FILEIO_O_APPEND)
135 if (
flags & FILEIO_O_RDONLY)
137 if (
flags & FILEIO_O_WRONLY)
139 if (
flags & FILEIO_O_RDWR)
156 if (mode & FILEIO_S_IFREG)
158 if (mode & FILEIO_S_IFDIR)
160 if (mode & FILEIO_S_IFCHR)
163 if (mode & FILEIO_S_IRUSR)
165 if (mode & FILEIO_S_IWUSR)
167 if (mode & FILEIO_S_IXUSR)
170 if (mode & FILEIO_S_IRGRP)
174 if (mode & FILEIO_S_IWGRP)
178 if (mode & FILEIO_S_IXGRP)
181 if (mode & FILEIO_S_IROTH)
184 if (mode & FILEIO_S_IWOTH)
188 if (mode & FILEIO_S_IXOTH)
201 case FILEIO_SEEK_SET:
204 case FILEIO_SEEK_CUR:
207 case FILEIO_SEEK_END:
222 if (!buf || !*buf || !**buf || !retlong)
224 c = strchr (*buf,
',');
228 c = strchr (*buf,
'\0');
229 while (strchr (
"+-", **buf))
235 for (*retlong = 0; **buf; ++*buf)
238 if (**buf >=
'0' && **buf <=
'9')
239 *retlong += **buf -
'0';
240 else if (**buf >=
'a' && **buf <=
'f')
241 *retlong += **buf -
'a' + 10;
242 else if (**buf >=
'A' && **buf <=
'F')
243 *retlong += **buf -
'A' + 10;
262 *retint = (
long) retlong;
272 if (!buf || !*buf || !**buf || !ptrval || !length)
274 c = strchr (*buf,
'/');
284 *length = (int) retlong;
327 sprintf (buf + strlen (buf),
"%x", retcode);
331 error = FILEIO_EINTR;
337 sprintf (buf + strlen (buf),
",%x",
error);
403 pathname = (
char *) alloca (length);
413 if (!stat (pathname, &st))
415 if (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
420 if (S_ISDIR (st.st_mode)
421 && ((
flags & O_WRONLY) == O_WRONLY || (
flags & O_RDWR) == O_RDWR))
473 off_t old_offset, new_offset;
500 length = (size_t) num;
509 static char *remaining_buf = NULL;
510 static int remaining_length = 0;
515 if (remaining_length > length)
517 memcpy (
buffer, remaining_buf, length);
518 memmove (remaining_buf, remaining_buf + length,
519 remaining_length - length);
520 remaining_length -= length;
525 memcpy (
buffer, remaining_buf, remaining_length);
526 xfree (remaining_buf);
527 remaining_buf = NULL;
528 ret = remaining_length;
545 if (ret > 0 && (
size_t)ret > length)
547 remaining_buf = (
char *)
xmalloc (ret - length);
548 remaining_length = ret - length;
549 memcpy (remaining_buf,
buffer + length, remaining_length);
562 old_offset = lseek (fd, 0,
SEEK_CUR);
564 if (ret < 0 && errno == EINTR)
566 new_offset = lseek (fd, 0,
SEEK_CUR);
569 if (old_offset != new_offset)
570 ret = new_offset - old_offset;
625 length = (size_t) num;
648 ret = write (fd,
buffer, length);
649 if (ret < 0 && errno == EACCES)
708 ret = lseek (fd,
offset, flag);
710 if (ret == (off_t) -1)
720 int old_len, new_len;
721 char *oldpath, *newpath;
723 struct stat ost, nst;
740 oldpath = (
char *) alloca (old_len);
748 newpath = (
char *) alloca (new_len);
756 of = stat (oldpath, &ost);
757 nf = stat (newpath, &nst);
758 if ((!of && !S_ISREG (ost.st_mode) && !S_ISDIR (ost.st_mode))
759 || (!nf && !S_ISREG (nst.st_mode) && !S_ISDIR (nst.st_mode)))
765 ret = rename (oldpath, newpath);
772 if (errno == ENOTEMPTY)
778 if (!of && !nf && S_ISDIR (nst.st_mode))
780 if (S_ISREG (ost.st_mode))
784 char oldfullpath[PATH_MAX];
785 char newfullpath[PATH_MAX];
788 cygwin_conv_path (CCP_WIN_A_TO_POSIX, oldpath, oldfullpath,
790 cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
792 len = strlen (oldfullpath);
793 if (IS_DIR_SEPARATOR (newfullpath[len])
794 && !filename_ncmp (oldfullpath, newfullpath, len))
825 pathname = (
char *) alloca (length);
834 if (!stat (pathname, &st) && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
840 ret = unlink (pathname);
874 pathname = (
char *) alloca (namelength);
881 ret = stat (pathname, &st);
889 if (!ret && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
943 memset (&st, 0,
sizeof (st));
947 st.st_uid = getuid ();
950 st.st_gid = getgid ();
952 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE 955 #if HAVE_STRUCT_STAT_ST_BLOCKS 958 if (!gettimeofday (&tv, NULL))
959 st.st_atime = st.st_mtime = st.st_ctime = tv.tv_sec;
961 st.st_atime = st.st_mtime = st.st_ctime = (time_t) 0;
965 ret = fstat (fd, &st);
993 struct fio_timeval ftv;
1015 ret = gettimeofday (&tv, NULL);
1059 char *cmdline = NULL;
1071 cmdline = (
char *) alloca (length);
1092 ret = system (cmdline);
1129 c = strchr (++buf,
',');
1133 c = strchr (buf,
'\0');
1178 if (ctrlc_pending_p)
1247 memset (st, 0,
sizeof (
struct stat));
1257 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE 1260 #if HAVE_STRUCT_STAT_ST_BLOCKS 1275 int val = strtoul (args, &arg_end, 10);
1277 if (*args && *arg_end ==
'\0')
1283 error (
_(
"Illegal argument for \"set remote system-call-allowed\" command"));
1290 error (
_(
"Garbage after \"show remote " 1291 "system-call-allowed\" command: `%s'"), args);
1302 _(
"Set if the host system(3) call is allowed for the target."),
1306 _(
"Show if the host system(3) call is allowed for the target."),
static int remote_fileio_resize_fd_map(void)
ssize_t read(int fd, void *buf, size_t count)
static mode_t remote_fileio_to_host_mode(fio_mode_t fnum)
static void remote_fileio_badfd(void)
#define FIO_FD_CONSOLE_IN
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
static void show_system_call_allowed(const char *args, int from_tty)
static unsigned int remote_fileio_to_host_uint(fio_uint_t fnum)
static void remote_fileio_return_errno(int retcode)
struct ui_file * gdb_stdtargin
void * memset(T *s, int c, size_t n)=delete
static void remote_fileio_func_unlink(char *buf)
static void remote_fileio_func_close(char *buf)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
static struct cmd_list_element * remote_show_cmdlist
static int remote_fileio_extract_int(char **buf, long *retint)
int putpkt(const char *buf)
static void remote_fileio_func_gettimeofday(char *buf)
void initialize_remote_fileio(struct cmd_list_element *remote_set_cmdlist, struct cmd_list_element *remote_show_cmdlist)
static int remote_fileio_next_free_fd(void)
static void remote_fileio_func_rename(char *buf)
static void remote_fileio_reply(int retcode, int error)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
static void remote_fileio_func_system(char *buf)
static void remote_fileio_func_write(char *buf)
static void host_to_fileio_time(time_t num, fio_time_t fnum)
#define CATCH(EXCEPTION, MASK)
static void host_to_fileio_uint(long num, fio_uint_t fnum)
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
static int remote_fileio_extract_long(char **buf, LONGEST *retlong)
void host_to_fileio_stat(struct stat *st, struct fio_stat *fst)
#define FIO_FD_CONSOLE_OUT
int host_to_fileio_error(int error)
static mode_t remote_fileio_mode_to_host(long mode, int open_call)
void() quit_handler_ftype(void)
static time_t remote_fileio_to_host_time(fio_time_t fnum)
static struct @152 remote_fio_func_map[]
void printf_unfiltered(const char *format,...)
void remote_fileio_reset(void)
static void host_to_bigendian(LONGEST num, char *buf, int bytes)
static int remote_fileio_init_fd_map(void)
static void remote_fileio_func_lseek(char *buf)
PTR xrealloc(PTR ptr, size_t size)
static struct @151 remote_fio_data
static int remote_fileio_fd_to_targetfd(int fd)
static ULONGEST remote_fileio_to_host_ulong(fio_ulong_t fnum)
static int remote_fio_system_call_allowed
quit_handler_ftype * quit_handler
static void remote_fileio_func_open(char *buf)
static int remote_fileio_map_fd(int target_fd)
static void remote_fileio_func_read(char *buf)
static void remote_fileio_to_fio_long(LONGEST num, fio_long_t fnum)
static void remote_fileio_close_target_fd(int target_fd)
static void remote_fileio_ioerror(void)
int check_quit_flag(void)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
void ui_file_write(struct ui_file *file, const char *buf, long length_buf)
long ui_file_read(struct ui_file *file, char *buf, long length_buf)
static void remote_fileio_func_fstat(char *buf)
static void remote_fileio_return_success(int retcode)
static int remote_fileio_oflags_to_host(long flags)
struct ui_file * gdb_stdtarg
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
void remote_fileio_to_host_stat(struct fio_stat *fst, struct stat *st)
static void remote_fileio_quit_handler(void)
unsigned long long ULONGEST
static struct cmd_list_element * remote_set_cmdlist
static void do_remote_fileio_request(char *buf)
static void remote_fileio_to_fio_timeval(struct timeval *tv, struct fio_timeval *ftv)
static quit_handler_ftype * remote_fileio_o_quit_handler
struct ui_file * gdb_stdtargerr
void gdb_flush(struct ui_file *file)
static void remote_fileio_func_stat(char *buf)
static int remote_fileio_seek_flag_to_host(long num, int *flag)
void error(const char *fmt,...)
static void remote_fileio_func_isatty(char *buf)
static int remote_fileio_extract_ptr_w_len(char **buf, CORE_ADDR *ptrval, int *length)
static void set_system_call_allowed(const char *args, int from_tty)
void remote_fileio_request(char *buf, int ctrlc_pending_p)