Novell Home

NSS06

From Developer Community

This code demonstrates how to read files with NSS APIs (NetWare)

Sample Code

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

int main( int argc, char* argv[]) {
  Key_t  root_key;
  NINT   task_id;
  Key_t  file_key;
  char   buffer[ 512];
  NINT   bytes_read;
  STATUS ccode;
  if ( argc != 2) {
    printf( "Usage: %s <filename>\n", argv[ 0]);
    return EXIT_FAILURE;
  }
  if (( ccode = zRootKey( 0, &root_key)) != zOK) {
    printf( "zRootKey failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zBeginTask( root_key, 0, &task_id)) != zOK) {
    zClose( root_key);
    printf( "zBeginTask failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zOpen( root_key, task_id, zNSPACE_LONG|zMODE_UTF8, argv[ 1], zRR_READ_ACCESS, &file_key)) != zOK) {
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zOpen failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zRead( file_key, zNILXID, 0, sizeof( buffer), buffer, &bytes_read)) != zOK) {
    zClose( file_key);
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zRead failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  printf( "Read %d bytes: \"%.*s\"\n", bytes_read, bytes_read, buffer);
  if (( ccode = zClose( file_key)) != zOK) {
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zClose failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zEndTask( root_key, task_id)) != zOK) {
    zClose( root_key);
    printf( "zEndTask failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zClose( root_key)) != zOK) {
    printf( "zClose failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.