www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/07/15/16:47:43

Message-Id: <199807152043.NAA16544@geocities.com>
From: cssl AT geocities DOT com
Sender: cssl AT mail DOT geocities DOT com
To: djgpp-workers AT delorie DOT com
Date: Sat, 11 Jul 1998 05:40:30 GMT0BST
MIME-Version: 1.0
Subject: FSEXT bug ?
Reply-to: Diego Zuccato <cssl AT geocities DOT com>

Getting strange results from FSEXT family of functions, I decided to 
investigate a bit, so I wrote a test program to see what really happens.
Well, I think that's NOT the correct behaviour. Please try this little 
program. Shouldn't it call WRITE only once ? Or at least once for every 
character, but it shouldn't call it with different parts of the same 
string ! Uh, try both WITH and WITHOUT the setvbuf(). Without it 
apparently the first character is lost.
Am I missing something ?

-------8<-------------------8<------------------8<------------------------
 
#include <stdio.h>
#include <io.h>
#include <sys/fsext.h>
#include <fcntl.h>

// handles open() and creat()
int _my_open_handler(__FSEXT_Fnumber, int *, va_list);

// handles all other funcs
int _my_handler(__FSEXT_Fnumber, int *, va_list);

static void __attribute__((constructor))
init_FSEXT(void)
{
 __FSEXT_add_open_handler(_my_open_handler);
};

int _my_open_handler(__FSEXT_Fnumber n, int *rv, va_list args)
{
 int my_handle;

 switch(n)
 {
  case __FSEXT_open:
			my_handle=__FSEXT_alloc_fd(_my_handler);
			printf("OPEN : Allocated handle #%d\n",my_handle);
			__FSEXT_set_function(my_handle,_my_handler);
			*rv=my_handle;
			break;
  case __FSEXT_creat:
			my_handle=__FSEXT_alloc_fd(_my_handler);
			printf("CREAT : Allocated handle #%d\n",my_handle);
			__FSEXT_set_function(my_handle,_my_handler);
			*rv=my_handle;
			break;
  default:
			printf("OOPS! Neither open() nor creat() ... :-(\n");
			return 0;
 };

 return 1;	// Call handled
};

int _my_handler(__FSEXT_Fnumber n, int *rv, va_list args)
{
 int our_handle=va_arg(args, int);
 int handled=1;

 printf(" -> ");	// tells when we're entering this fn

 // Just for testing !
 *rv=10;

 switch(n) {
  case __FSEXT_nop:	// Handled, but nothing done
			printf("Uh ? Please, tell me how you went here !\n");
		 	break;
  case __FSEXT_read:
			printf("READ: handle #%d\n",our_handle);
			break;
  case __FSEXT_write: {
			char *b=va_arg(args, char*);
			int n=va_arg(args, int);
			printf("WRITE: handle #%d : ",our_handle);
			printf("buf=\"%s\", nbyte=%d\n", b, n);
			};
			break;
  case __FSEXT_ready:
			printf("READY: handle #%d\n",our_handle);
			break;
  case __FSEXT_close:
			printf("CLOSE: handle #%d\n",our_handle);
			handled=0; // Don't handle close any more !
			break;
  default:
			printf("Something REALLY BAD happened !!!");
			printf("Called _my_handler fn #%d on handle #%d\n",
				n, our_handle);
			exit(1);	// ARGH!
 };
 return handled;
};

int main(void)
{
  FILE *hnd;
  char buff[10];

  printf("\nfopen : ");  hnd= fopen("!.tst", "r+b");
/*  setvbuf(hnd, NULL, _IONBF, 0);*/
  printf("\nfgets : ");       fgets(buff, 10, hnd);
  printf("\nfputs : ");       fputs("Hello, world ! I'm here !", hnd);
  printf("\nfclose: ");       fclose(hnd);
};

-------8<-------------------8<------------------8<------------------------

BYtE,
 Diego.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019