samples/common/MoNet/util/mtnfile/main.cc

Go to the documentation of this file.
00001 //
00002 // Copyright 2002 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 
00012 #include <sys/stat.h>
00013 #include <unistd.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <MTNFile.h>
00017 
00018 main(int argc, char** argv)
00019 {
00020     if (argc != 2) {
00021         fprintf(stderr, "Usage: mtnfile file.mtn\n");
00022         exit(1);
00023     }
00024 
00025     struct stat st;
00026     if (stat(argv[1], &st) != 0) {
00027         perror("stat");
00028         exit(1);
00029     }
00030     
00031     MTNFile* mtnfile = (MTNFile*)malloc(st.st_size);
00032     if (mtnfile == 0) {
00033         fprintf(stderr, "malloc() failed.\n");
00034         exit(1);
00035     }
00036     
00037     FILE* fp = fopen(argv[1], "rb");
00038     if (fp == 0) {
00039         fprintf(stderr, "can't open %s\n", argv[1]);
00040         exit(1);
00041     }
00042     
00043     if (fread((void*)mtnfile, 1, st.st_size, fp) != st.st_size) {
00044         fprintf(stderr, "fread() failed.\n");
00045         fclose(fp);
00046         exit(1);
00047     }
00048 
00049     fclose(fp);
00050 
00051     mtnfile->Print();
00052 }

Generated on Sun Dec 2 23:04:29 2007 for openSDK by  doxygen 1.3.9.1