delorie.com/djgpp/doc/libc/libc_362.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

__FSEXT_set_function

Syntax

 
#include <sys/fsext.h>

int __FSEXT_set_function(int _fd, __FSEXT_Function *_function);

Description

This function is part of the File System Extensions. It is used to set the handler function for those extensions that use DOS files for I/O. One situation where you might need this is when you must catch output to the terminal and play some tricks with it, like colorize it or redirect it to another device.

Return Value

Zero in case of success, non-zero in case of failure (like if _fd is negative).

Portability

ANSI/ISO C No
POSIX No

Example

 
#include <sys/fsext.h>
#include <conio.h>

/* A simple example of a write handler which converts DOS I/O to the
   screen into direct writes to video RAM.  */
static int
my_screen_write (__FSEXT_Fnumber func, int *retval, va_list rest_args)
{
  char *buf, *mybuf;
  size_t buflen;
  int fd = va_arg (rest_args, int);

  if (func != __FSEXT_write || !isatty (fd))
    return 0;  /* and the usual DOS call will be issued */

  buf = va_arg (rest_args, char *);
  buflen = va_arg (rest_args, size_t);
  mybuf = alloca (buflen + 1);
  memcpy (mybuf, buf, buflen);
  mybuf[buflen] = '\0';
  cputs (mybuf);
  *retval = buflen;
  return 1;  /* meaning that we handled the call */
}

/* Install our handler.  The `attribute constructor' causes this
   function to be called by the startup code.  */
static void __attribute__((constructor))
install_screen_write_handler (void)
{
  __FSEXT_set_function (fileno (stdout), my_screen_write);
}


  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004