This code demonstrates how to write to files with NSS APIs (NetWare)
#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 data[] = "Hello World";
NINT bytes_written;
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) {
zEndTask( root_key, task_id);
zClose( root_key);
printf( "zBeginTask failed, ccode = %d\n", ccode);
return EXIT_FAILURE;
}
if (( ccode = zCreate( root_key, task_id, zNILXID, zNSPACE_LONG|zMODE_UTF8, argv[ 1],
zFILE_REGULAR, 0, 0, zRR_WRITE_ACCESS, &file_key)) != zOK) {
zEndTask( root_key, task_id);
zClose( root_key);
printf( "zCreate failed, ccode = %d\n", ccode);
return EXIT_FAILURE;
}
if (( ccode = zWrite( file_key, zNILXID, 0, sizeof( data), data, &bytes_written)) != zOK) {
zClose( file_key);
zEndTask( root_key, task_id);
zClose( root_key);
printf( "zWrite failed, ccode = %d\n", ccode);
return EXIT_FAILURE;
}
printf( "Written %d of %d bytes\n", bytes_written, sizeof( data));
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;
}
© 2008 Novell, Inc. All Rights Reserved.