Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HDFS >> mail # dev >> hdfs.h C API


Hey all

I am trying to use the c api to access hdfs:

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

#include <string.h>
#include <assert.h>

#include <hdfs.h>

int main (int argc, char ** argv)
{
  hdfsFS fs = hdfsConnect ("default", 0);
  assert (fs);

  const char * wp = "test";
  hdfsFile wf = hdfsOpenFile (fs, wp, O_WRONLY | O_CREAT,
                              0, 0, 0);
  if (!wf)
    {
      fprintf (stderr, "Failed to open %s for writing!\n", wp);
      exit (-1);
    }

  const char * buffer = "Hello, World!";
  tSize num_written_bytes = hdfsWrite (fs, wf, (void *) buffer,
                                       strlen (buffer) + 1);
  assert (num_written_bytes);
  if (hdfsFlush (fs, wf))
    {
      fprintf (stderr, "Failed to 'flush' %s\n", wp);
      exit (-1);
    }
  hdfsCloseFile(fs, wf);

  return 0;
}

--

gcc t.c -lhdfs -lpthread -L/usr/java/default/lib/amd64/server -ljvm -Wall

But i am getting:

Environment variable CLASSPATH not set!
getJNIEnv: getGlobalJNIEnv failed
a.out: t.c:12: main: Assertion `fs' failed.
Aborted

Not sure what i need to do now to get this example working.

--Phil