21 #include <sys/types.h>
35 unsigned char *lbuf = buf;
39 int read_until_null = !length;
61 if (lseek64(fd,addr,SEEK_SET) == (off64_t) -1) {
62 verror(
"lseek64(%d,0x%"PRIxADDR",0): %s\n",fd,addr,strerror(errno));
67 retval = read(fd,lbuf+rc,bufsiz - rc);
70 if (rc < bufsiz && !read_until_null) {
73 else if (read_until_null
74 && (len = strnlen((
const char *)lbuf,rc)) < rc) {
76 if (!(lbuf = (
void *)
realloc(lbuf,len + 1))) {
78 verror(
"realloc: %s\n",strerror(errno));
83 else if (read_until_null && rc == bufsiz) {
85 if (!(lbuf = (
void *)
realloc(lbuf,bufsiz + bufinc))) {
86 tbuf =
malloc(bufsiz + bufinc);
90 verror(
"malloc: %s\n",strerror(errno));
93 memcpy(tbuf,lbuf,bufsiz);
99 else if (!read_until_null && rc == bufsiz) {
104 else if (retval == 0 && rc != bufsiz) {
107 verror(
"EOF before reading %d bytes!\n",bufsiz);
112 && retval != EAGAIN && retval != EINTR) {
115 verror(
"read: %s\n",strerror(errno));
127 unsigned long length,
128 unsigned char *buf) {
132 if (lseek64(fd,addr,0) == (off_t)-1) {
133 verror(
"lseek64: %s",strerror(errno));
138 rc = write(fd,buf+total,length-total);
139 if (rc > 0 && (total + rc) == length) {
143 else if ((rc > 0 && rc < length)
144 || (rc <= 0 && (rc == EAGAIN || rc == EINTR)))
147 verror(
"write error: %s (after %ld bytes of %lu total) (buf 0x%p)\n",
148 strerror(errno),total,length,(
void *)buf);
unsigned char * target_generic_fd_read(int fd, ADDR addr, unsigned long length, unsigned char *buf)
#define verror(format,...)
#define vdebug(devel, areas, flags, format,...)
void * realloc(void *ptr, size_t size)
unsigned long target_generic_fd_write(int fd, ADDR addr, unsigned long length, unsigned char *buf)
void * malloc(size_t size)