Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- libc - <b>__fsext_set_function</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
__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).

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);
     }


See Also: File System Extensions

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson