Giter Club home page Giter Club logo

memorymapping's Introduction

fmemopen for Mac OS and iOS

Originally ported from ingenuitas python-tesseract. Ported by Jeff Verkoeyen under the Apache 2.0 License.

From the fmemopen man page:

FILE *fmemopen(void *buf, size_t size, const char *mode);

The fmemopen() function opens a stream that permits the access specified by mode. The stream allows I/O to be performed on the string or memory buffer pointed to by buf. This buffer must be at least size bytes long.

Alas, this method does not exist on BSD operating systems (specifically Mac OS X and iOS). It is possible to recreate this functionality using a BSD-specific method called funopen.

From the funopen man page:

FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int), fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));

The funopen() function associates a stream with up to four ``I/O functions''. Either readfn or writefn must be specified; the others can be given as an appropriately-typed NULL pointer. These I/O functions will be used to read, write, seek and close the new stream.

fmemopen.c provides a simple implementation of fmemopen using funopen so that you can create FILE pointers to blocks of memory.

Adding it to your Project

Drag fmemopen.h and fmemopen.c to your project and add them to your target. #include "fmemopen.h" wherever you need to use fmemopen.

Examples

#import "fmemopen.h"

NSString* string = @"fmemopen in Objective-C";
const char* cstr = [string UTF8String];
FILE* file = fmemopen((void *)cstr, sizeof(char) * (string.length + 1), "r");

// fread on file will now read the contents of the NSString

fclose(file);

memorymapping's People

Contributors

jverkoey avatar tmm1 avatar derphilipp avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.