Repository: celix Updated Branches: refs/heads/feature/CELIX-237_rsa-ffi c97d16746 -> eb31d9d97
Reversed memstream/fmemopen source to orignal source not explicitlty stating License Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/0153dd2c Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/0153dd2c Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/0153dd2c Branch: refs/heads/feature/CELIX-237_rsa-ffi Commit: 0153dd2cd705d99f3a38e4bdf17dfb8e3fc4ea7c Parents: c97d167 Author: Pepijn Noltes <[email protected]> Authored: Tue Jul 7 21:11:15 2015 +0200 Committer: Pepijn Noltes <[email protected]> Committed: Tue Jul 7 21:11:15 2015 +0200 ---------------------------------------------------------------------- .../memstream/README.md | 49 ++++++++++++++++++++ .../memstream/fmemopen.c | 4 +- .../memstream/open_memstream.c | 8 +--- .../memstream/open_memstream.h | 4 -- 4 files changed, 52 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/0153dd2c/remote_services/dynamic_function_interface/memstream/README.md ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/memstream/README.md b/remote_services/dynamic_function_interface/memstream/README.md new file mode 100644 index 0000000..476810e --- /dev/null +++ b/remote_services/dynamic_function_interface/memstream/README.md @@ -0,0 +1,49 @@ +fmemopen for Mac OS and iOS +=========================== + +Originally ported from [ingenuitas python-tesseract](https://github.com/ingenuitas/python-tesseract/blob/master/fmemopen.c). 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 +======== + +```obj-c +#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); +``` http://git-wip-us.apache.org/repos/asf/celix/blob/0153dd2c/remote_services/dynamic_function_interface/memstream/fmemopen.c ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/memstream/fmemopen.c b/remote_services/dynamic_function_interface/memstream/fmemopen.c index 40c377d..926ce36 100644 --- a/remote_services/dynamic_function_interface/memstream/fmemopen.c +++ b/remote_services/dynamic_function_interface/memstream/fmemopen.c @@ -1,6 +1,4 @@ /* - * Licensed under Apache License v2. See LICENSE for more information. - * * fmem.c : fmemopen() on top of BSD's funopen() * 20081017 AF */ @@ -77,4 +75,4 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) mem->size = size, mem->buffer = buf; return funopen(mem, readfn, writefn, seekfn, closefn); } -#endif +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/0153dd2c/remote_services/dynamic_function_interface/memstream/open_memstream.c ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/memstream/open_memstream.c b/remote_services/dynamic_function_interface/memstream/open_memstream.c index 20bb93f..6bc4f01 100644 --- a/remote_services/dynamic_function_interface/memstream/open_memstream.c +++ b/remote_services/dynamic_function_interface/memstream/open_memstream.c @@ -1,8 +1,4 @@ -/* - * Licensed under Apache License v2. See LICENSE for more information. - * - * Use funopen(3) to provide open_memstream(3) like functionality. - */ +/* Use funopen(3) to provide open_memstream(3) like functionality. */ #include <stdio.h> #include <stdlib.h> @@ -131,4 +127,4 @@ open_memstream(char **cp, size_t *lenp) errno = save_errno; } return (fp); -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/celix/blob/0153dd2c/remote_services/dynamic_function_interface/memstream/open_memstream.h ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/memstream/open_memstream.h b/remote_services/dynamic_function_interface/memstream/open_memstream.h index 2a38e12..e87bb0a 100644 --- a/remote_services/dynamic_function_interface/memstream/open_memstream.h +++ b/remote_services/dynamic_function_interface/memstream/open_memstream.h @@ -1,7 +1,3 @@ -/* - * Licensed under Apache License v2. See LICENSE for more information. - * - */ #ifndef OPEN_MEMSTREAM_H_ #define OPEN_MEMSTREAM_H_
