Originally Posted by
C_ntua
fopen() and fseek() are standard functions. read(), write(), open(), lseek() are no-standard, so the aren't generally portable. As a first note you are better with fopen(), fseek(), fread() etc etc.
In Linux a proper code should work. So you can post the code and ppl can find the problem.
Embedded systems vary. There are not standard things for them when it comes to the I/O operations and the filesystem.
FILE is a type defined somewhere. It could be an int, it could be a long. Or a struct. I would guess it is an int, but I have no idea for sure. But why not use fseek() and fopen()? Why not use the standard functions?
Does it read lets say one character? Does it give an error when searching in certain sections? Do you try to see if the functions succeed from their return code??
To answer some of your questions
Yes i am using fseek and fopen and fread. And it is them that are giving me the problem.
Yes i am monitoring the return codes of these functions.. It typically fails when trying to seek. You have to understand that this is a huge library (libdvdnav) which i'm trying to port. I'm modifying the underlying physical layer so that the reading part syncs with the filesystem that i have.
To show you some of the modifications that i'm doing.
Code:
static dvd_input_t file_open(const char *target)
{
dvd_input_t dev;
/* Allocate the library structure */
dev = (dvd_input_t) malloc(sizeof(*dev));
if(dev == NULL) {
fprintf(stderr, "libdvdread: Could not allocate memory.\n");
return NULL;
}
#if 0
/* Open the device */
#ifndef WIN32
dev->fd = open(target, O_RDONLY);
#else
dev->fd = open(target, O_RDONLY | O_BINARY);
#endif
#endif
dev->fd = fopen(target,"r");
if(dev->fd < 0) {
perror("libdvdread: Could not open input");
free(dev);
return NULL;
}
return dev;
}
The commented part was what was initially there.
The problem is that it is able to read in general and its reading and giving me few chars and all properly. But when it tries to seek there is a error and it returns saying cant seek to sector %d.
Code:
static int file_seek(dvd_input_t dev, int blocks)
{
off_t pos;
//pos = lseek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET);
pos = fseek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET);
if(pos < 0) {
return pos;
}
/* assert pos % DVD_VIDEO_LB_LEN == 0 */
return (int) (pos / DVD_VIDEO_LB_LEN);
}
Again where his fd is a int while mine is a FILE*.
My question is is this kind of transformation ok? or should i take into account something else?
This modified code fails in linux as well.
Thanks for your comments..