Plan 9 from Bell Labs’s /usr/web/sources/contrib/staal1978/ports/src/fmemopen_simple.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/* copied from haiku patch to tuxpaint by
 * Pere Pujal 
 * http://permalink.gmane.org/gmane.comp.gnu.tuxpaint.devel/1604
 * adjusted to plan9/ape
 */

#define _PLAN9_SOURCE

#include <u.h>
#include <stdlib.h>
#include <stdio.h>


FILE * fmemopen(unsigned char * data, size_t size, const char * mode)
{
  unsigned int i;
  char *fname;
  FILE * fi = tmpfile();

    fname = tmpnam(0);


  fi = fopen(fname, "w");
  if (fi == NULL)
    {
      free(fname);
      return(NULL);
    }

  for (i = 0; i < size; i++)
    {
      fwrite(data, 1, 1, fi);
      data ++;
    }
  
  fclose(fi);
  fi = fopen(fname, mode);
  free(fname);
  return(fi);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.