This code demonstrates how to create files larger than 4 GB with NSS APIs (NetWare). Use sample NSS09 to read the created file back and verify the information in it.
#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[ 1024];
size_t i;
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 = 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;
}
/* initialize the buffer */
for ( i = 1; i < sizeof( data); ++i) {
data[ i] = ( char) i;
}
/* write 5G */
for ( i = 0; i < 5 * 1024 * 1024; ) {
NINT bytes_written;
if ( i % ( 1024 * 1024) == 0) {
data[ 0] = ( char) ( i / ( 1024 * 1024));
}
if (( ccode = zWrite( file_key, zNILXID, i * ( unsigned __int64) sizeof( data), 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;
}
if ( bytes_written != sizeof( data)) {
zClose( file_key);
zEndTask( root_key, task_id);
zClose( root_key);
printf( "bytes_written != sizeof( data): %d %d\n", bytes_written, sizeof( data));
return EXIT_FAILURE;
}
++i;
if ( i % 1024 == 0) {
printf( "Written %uM\n", i / 1024);
}
}
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;
}
© 2009 Novell, Inc. All Rights Reserved.