ne_get_range directly to char array buffer

Jordi Mueters jordimueters at
Tue Apr 11 12:20:49 EDT 2017

Okay so I am still at kernel 3.10 unfortunately but I get what you're trying to say.

Just to see how it works I simply use open, then mmap and then ne_get_range with the file descriptor returned by open.

Here's the code I'm using:

ne_content_range range;
range.start = offset;
range.end = offset + (size - 1);

int fd = open("/tmp/neon-buffer", O_RDWR | O_CREAT | O_EXCL, S_IRWXU);
if(fd == -1) {
return 0;

mmap(buf, size, PROT_READ, MAP_FIXED | MAP_PRIVATE, fd, 0);

int ret = ne_get_range(sess, ne_path_escape(ne_concat(parsed_uri.path, path + 1, NULL)), &range, fd);
 if(ret == NE_ERROR) {
return 0;

I removed an unlink and munmap call I had right after ne_get_range to see if the temp file would contain actual data.

Unfortunately my temp file is empty after calling ne_get_range... Any suggestions?

Van: neon-bounces at <neon-bounces at> namens Jordi Mueters <jordimueters at>
Verzonden: dinsdag 11 april 2017 16:09:49
Aan: Henrik Holst
CC: neon at
Onderwerp: Re: ne_get_range directly to char array buffer

Unfortunately I can't do that. fileno returns -1 when you request the file descriptor of a FILE created by fmemopen.

Quote from the Linux Programmer's Manual:

There is no file descriptor associated with the file stream returned
by this function (i.e., fileno(3) will return an error if called on
the returned stream).

Van: Henrik Holst <henrik.holst at>
Verzonden: dinsdag 11 april 2017 16:07:53
Aan: Jordi Mueters
CC: neon at
Onderwerp: Re: ne_get_range directly to char array buffer


  you can use fileno(3) in order to get the filedescriptor from a FILE pointer. "int fileno(FILE *stream);"


2017-04-11 15:40 GMT+02:00 Jordi Mueters <jordimueters at<mailto:jordimueters at>>:

Hi all, hope someone can help me with the following.

I am using ne_get_range to read part of a file on webdav.

This method requires a file descriptor.

I, however, have no interest in reading into an actual file, I want the content to stay in memory (preferably directly written directly into a char array I manage).

My thinking is that I can create a pointer to a FILE using  fmemopen. Unfortunately fmemopen returns a FILE which does not have a file descriptor.

The proposal is to overload ne_get_range to accept a FILE pointer instead of a file descriptor. This won't break any functionality because I'm sure everyone has to call fileno to get the filedescriptor anyways and with the change they don't have to anymore.

If anyone has a more suitable solution (to read the range directly into my char array) please let me know.

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the neon mailing list