This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fopencookie problem in glibc 2.3.5?


Hi,

On glibc 2.3.5 (Linux 2.6.11, ppc32, x86) I'm getting different behaviour than on
2.3.4 when using fopencookie. Example program attached.

On glibc 2.3.4:
[arekm@perfo1 arekm]$ gcc testcookie.c -Wall -O2; ./a.out .bashrc
1: ftell 0
2: fseek ret: 0 ftell 0
3: fseek ret: 0 ftell 5
4: char: s fread ret: 1 ftell: 6

On glibc 2.3.5:
[arekm@iarm ~]$ gcc testcookie.c -Wall -O2 ; ./a.out .bashrc
1: ftell 0
2: fseek ret: 0 ftell 0
3: fseek ret: 0 ftell 0
4: char: đ fread ret: 1 ftell: -1

Could anyone try to run it on 2.3.5? Thanks.

# define _GNU_SOURCE 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <zlib.h>
#include <libio.h>

static size_t myread(void* myhandle, char* buffer, size_t size)
{
  return fread(buffer, 1, size, (FILE*)myhandle);
}
static size_t mywrite(void* myhandle, char* buffer, size_t size)
{
  return fwrite(buffer, 1, size, (FILE*)myhandle);
}
static int myseek(void* myhandle, fpos_t* position, int whence)
{
  return fseek((FILE*)myhandle, *(unsigned int*)position, whence);
}
static int myclose(void* myhandle)
{
  return fclose((FILE*)myhandle);
}

cookie_io_functions_t myfunctions =
{ 
  (cookie_read_function_t*)myread, 
  (cookie_write_function_t*)mywrite, 
  (cookie_seek_function_t*)myseek, 
  (cookie_close_function_t*)myclose
};

int main(int argc, char *argv[])
{
    char *path = argv[1];
    FILE *zstream;
    FILE *stream;
    int c, d;
    
    if ((zstream = fopen(path, "r")) != NULL) {
        stream = fopencookie(zstream, "r", myfunctions);
	if (!stream) {
		printf("fopencookie failed\n");
		return 1;
	}
        printf("1: ftell %ld\n", ftell(stream));
	d = fseek(stream, 0, SEEK_CUR);
	printf("2: fseek ret: %d ftell %ld\n", d, ftell(stream));
	d = fseek(stream, 5, SEEK_SET);
	printf("3: fseek ret: %d ftell %ld\n", d, ftell(stream));
        d = fread(&c, 1, 1, stream);
        printf("4: char: %c fread ret: %d ftell: %ld\n", (unsigned char)c, d, ftell(stream));
	fclose(zstream);
    }
    return 1;
}


-- 
Arkadiusz Miśkiewicz                    PLD/Linux Team
http://www.t17.ds.pwr.wroc.pl/~misiek/  http://ftp.pld-linux.org/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]