Exemplo n.º 1
0
Arquivo: mod.c Projeto: ntj/rockbox
bool get_mod_metadata(int fd, struct mp3entry* id3)
{    
    /* Use the trackname part of the id3 structure as a temporary buffer */
    unsigned char buf[1084];
    int read_bytes;
    char *p;
      

    if ((lseek(fd, 0, SEEK_SET) < 0) 
         || ((read_bytes = read(fd, buf, sizeof(buf))) < 1084))
    {
        return false;
    }
    
    /* We don't do file format checking here
     * There can be .mod files without any signatures out there */

    p = id3->id3v2buf;
    
    /* Copy Title */
    strcpy(p, &buf[0x00]);
    id3->title = p;
    p += strlen(p)+1;

    id3->bitrate = filesize(fd)/1024; /* size in kb */
    id3->frequency = 44100;
    id3->length = 120*1000;
    id3->vbr = false;
    id3->filesize = filesize(fd);
        
    return true;
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
	char *path;
	int opt;
	while((opt = getopt(argc, argv, "s:")) != -1){
		switch(opt){
		case 's':
			scmcap = filesize(optarg);
			if(scmcap == -1)
				exit(1);
			scm = malloc(scmcap);
			scmlen = readfile(optarg, scm, scmcap);
			if(scmlen < scmcap){
				fprintf(stderr, "error reading %s\n", optarg);
				exit(1);
			}
			if(jsonparse(&scmroot, scm, scmlen) == -1){
				fprintf(stderr, "error parsing %s\n", optarg);
				exit(1);
			}
			break;
		default:
		caseusage:
			fprintf(stderr, "usage: %s [-s path/to/schema.json] file.json\n", argv[0]);
			exit(1);
		}
	}
	if(optind >= argc)
		goto caseusage;

	path = argv[optind];
	doccap = filesize(path);
	doc = malloc(doccap);
	doclen = readfile(path, doc, doccap);
	if(doclen < doccap){
		fprintf(stderr, "error reading %s\n", path);
		exit(1);
	}

	if(jsonparse(&docroot, doc, doclen) == -1){
		fprintf(stderr, "error parsing %s\n", path);
		exit(1);
	}

	if(scm != NULL){
		if(jsonrefs(&scmroot) == -1){
			fprintf(stderr, "jsonrefs: fail for schema\n");
			exit(1);
		}
		if(jsoncheck(&docroot, 0, &scmroot, 0) == -1){
			fprintf(stderr, "type checking failed for '%s'\n", path);
			exit(1);
		}
	}

	return 0;
}
propertiesDialog::propertiesDialog(threadParam *p ,QIcon *icon,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::propertiesDialog)
{
    ui->setupUi(this);
    setFixedSize(size());
    param=p;
    if (p->files.size()>1){
        ui->nameLabel->setText(trUtf8("(несколько элементов)"));
        ui->label_6->setText(trUtf8("Размещение: "));
        ui->pathLabel->setText(p->source);

        ui->label_8->setText(trUtf8("Кол-во элементов: "));
        ui->typeLabel->setText(trUtf8("файлов: ") + QString().number(p->count_files)+
                               trUtf8(" папок: ")+QString().number(p->count_dirs));
        ui->sizeLabel->setText(filesize(p->total_size));
        ui->time1Label->setText(trUtf8("(несколько элементов)"));
        ui->time2Label->setText(trUtf8("(несколько элементов)"));
    } else {


        ui->nameLabel->setText(p->files.first().fileName());
        ui->pathLabel->setText(p->files.first().absolutePath());
        if (p->files.first().isDir()) ui->sizeLabel->setText(filesize(p->total_size)+trUtf8(", папок: ")+
                                                             QString().number(p->count_dirs)+trUtf8(" файлов: ")+
                                                             QString().number(p->count_files));
        else ui->sizeLabel->setText(filesize(p->total_size));

        if (p->files.first().isSymLink()){
            ui->typeLabel->setText(QFileIconProvider().type(p->files.first())+trUtf8(" (ссылка)"));
            ui->label_12->setText(trUtf8("Ссылка на: "));
            ui->linkLabel->setText(param->files.first().symLinkTarget());
        }
        else{
            ui->typeLabel->setText(QFileIconProvider().type(p->files.first())) ;

        }

        ui->time1Label->setText(p->files.first().lastModified().toString("hh:mm:ss, dd MMM yyyy"));
        ui->time2Label->setText(p->files.first().lastRead().toString("hh:mm:ss, dd MMM yyyy"));

        showPermissions();
        ui->label_11->setPixmap(icon->pixmap(48,48));
    }

    connect(ui->u_read,SIGNAL(stateChanged(int)),this,SLOT(changged()));
    connect(ui->u_write,SIGNAL(stateChanged(int)),this,SLOT(changged()));
    connect(ui->u_exec,SIGNAL(stateChanged(int)),this,SLOT(changged()));

    connect(ui->g_read,SIGNAL(stateChanged(int)),this,SLOT(changged()));
    connect(ui->g_write,SIGNAL(stateChanged(int)),this,SLOT(changged()));
    connect(ui->g_exec,SIGNAL(stateChanged(int)),this,SLOT(changged()));

    connect(ui->o_read,SIGNAL(stateChanged(int)),this,SLOT(changged()));
    connect(ui->o_write,SIGNAL(stateChanged(int)),this,SLOT(changged()));
    connect(ui->o_exec,SIGNAL(stateChanged(int)),this,SLOT(changged()));

}
Exemplo n.º 4
0
char* readfile(const char* filename)
{
	char* ptr;
    FILE* file = fopen(filename, "r");
	if (file == NULL) exit(EXIT_FAILURE);
	ptr = malloc(filesize(file) * sizeof(char));
	fread(ptr, filesize(file), 1, file);
    return ptr;
}
Exemplo n.º 5
0
/* Read in the setllar mass bins from the
 * user-supplied file listed in the hod.bat file.
 */
void input_stellar_mass_bins()
{
  FILE *fp;
  int i,j,n;

  if(!Task.clustering && !Task.populate_sim)goto INPUT_LENSING_FILES;
  if(!Files.UseStellarMassBinsClustering)
    {
      fprintf(stdout,"No StellarMassBins file specified for clustering, using defaults:\nlog(M0) = 9, with 0.5 dex increments up to 12.0\n");
      wpl.nsamples = (12-9)/0.5;
      for(i=1;i<=wpl.nsamples;++i)
	{
	  wpl.mstar_wplo[0][i] = 9.0 + 0.5*i;
	  wpl.mstar_wphi[0][i] = 9.5 + 0.5*i;
	}
    }
  else
    {
      fprintf(stdout,"Opening file: [%s]\n",Files.StellarMassBinsClustering);
      fp = openfile(Files.StellarMassBinsClustering);
      wpl.nsamples = filesize(fp);
      
      printf("Reading %d stellar mass bins.\n",wpl.nsamples);
      for(i=1;i<=wpl.nsamples;++i)
	fscanf(fp,"%lf %lf",&wpl.mstar_wplo[0][i], &wpl.mstar_wphi[0][i]);
      fclose(fp);
    }

 INPUT_LENSING_FILES:
  if(!Task.lensing)return;
  if(!Files.UseStellarMassBinsLensing)
    {
      fprintf(stdout,"No StellarMassBins file specified for lensing, using defaults:\nlog(M0) = 9, with 0.5 dex increments up to 12.0\n");
      wpx.nsamples = (12-9)/0.5;
      for(i=1;i<=wpx.nsamples;++i)
	{
	  wpx.mstar_wplo[0][i] = 9.0 + 0.5*i;
	  wpx.mstar_wphi[0][i] = 9.5 + 0.5*i;
	}
    }
  else
    {
      fprintf(stdout,"Opening file: [%s]\n",Files.StellarMassBinsLensing);
      fp = openfile(Files.StellarMassBinsLensing);
      wpx.nsamples = filesize(fp);
      
      printf("Reading %d stellar mass bins.\n",wpx.nsamples);
      for(i=1;i<=wpx.nsamples;++i)
	fscanf(fp,"%lf %lf",&wpx.mstar_wplo[0][i], &wpx.mstar_wphi[0][i]);
      fclose(fp);
    }

}
Exemplo n.º 6
0
int main (int argc, char **argv)
{
	int pid;
	char qactivefile [256];
	char *progname = argv[0];

	openlog ("mdmn", 0, LOG_MAIL);
	umask (002);
	if (argc > 1 && !strcmp (argv[1], "-d")) {
		++debug;
		++argv;
		--argc;
	}
	if (argc > 2) {
		fprintf (stderr, "usage: %s [-d] [config-file]\n", progname);
		exit (-1);
	}
	if (! config (argv [1])) {
		fprintf (stderr, "cannot read config file\n");
		exit (-1);
	}

	if (! debug) {
		/* let's fork */
		pid = fork ();
		if (pid < 0) {
			fprintf (stderr, "%s: cannot fork\n", progname);
			exit (-1);
		}
		if (pid)
			exit (0);
		/* now we are a child */

		/* catch signals */
		sigign ();
	}
	/* make temp file name */
	mktemp (tmpf);

	syslog (LOG_INFO, "daemon started");

	sprintf (qactivefile, "%s/queueactive", SERVDIR);
	for (;;) {
		if (filesize (MAILBOX))
			runqueuer ();
		if (filesize (qactivefile))
			runbatcher ();
		sleep (DAEMONDELAY);
	}

	/* NOTREACHED */
}
Exemplo n.º 7
0
int main(int argc, char *argv[]) {

   /*
    Lavora sulla directory corrente se non si forniscono argomenti in input
   */
   if (argc == 1)
      filesize(".");
   else
      while (--argc > 0)
      	 filesize(*++argv);
   
   return(EXIT_SUCCESS);
}
Exemplo n.º 8
0
void getfilestats(file_t *file)
{
  file->size = filesize(file->d_name);
  file->inode = getinode(file->d_name);
  file->device = getdevice(file->d_name);
  file->mtime = getmtime(file->d_name);
}
Exemplo n.º 9
0
/* Inserisce len byte nel file f dalla posizione pos (=sposta avanti una parte del file); o aggiunge, se pos==end */
void insert(FILE *f, ULONG pos, ULONG len)
{
#define BLOCK 65535
 char buf[BLOCK];
 ULONG start, end, tomove, blks;

 end = filesize(f);
 tomove = end-pos; /* byte da spostare */
 start = tomove>BLOCK? end-BLOCK : end-tomove; /* posizione iniziale del blocco da spostare */

 if (start==end) goto dontmove;

 for (blks=tomove/BLOCK; blks; start-=BLOCK,blks--)
 {
  fseek(f,start,SEEK_SET);
  fread(buf,1,BLOCK,f);
  fseek(f,start+len,SEEK_SET);
  fwrite(buf,1,BLOCK,f);
 }
 /* Sposta gli ultimi byte */
 tomove %= BLOCK;
 fseek(f,pos,SEEK_SET);
 fread(buf,1,tomove,f);
 fseek(f,pos+len,SEEK_SET);
 fwrite(buf,1,tomove,f);
 return;

dontmove:
 /* Inserisce alla fine del file */
 fseek(f,start+len-1,SEEK_SET);
 fwrite(buf,1,1,f);
}
Exemplo n.º 10
0
int on_create(const struct inotify_event *evt, const char *src_name, const size_t src_size)
{
  char *dst_name;
  size_t dst_size;
  
  if (evt->mask & IN_CREATE) {
    /* Check if USB device */
    printf("CREATE %s\n", evt->name);
    if (strncmp("usb-", evt->name, 4) == 0) {
      dst_name = (char*)alloca(strlen(dev_path) + strlen(evt->name) + 2);
      sprintf(dst_name, "%s/%s", dev_path, evt->name);
      
      /* Check if correct size */
      if ((dst_size = filesize(dst_name)) == -1) {
	perror(__func__);
	return -1;
      }

      printf("Found %s size %lld\n", dst_name, dst_size);

      if (dst_size == src_size) {
	copy_usb(src_name, dst_name);
	return 1;
      }
    }
  }
  return 0;
}
Exemplo n.º 11
0
static bool
archive_ordinary_file (const char *file_name, int file_fd,
                       int archive_fd, bool *write_error)
{
  bool read_error = false;
  bool success = true;
  int file_size = filesize (file_fd);

  if (!write_header (file_name, USTAR_REGULAR, file_size,
                     archive_fd, write_error))
    return false;

  while (file_size > 0)
    {
      static char buf[512];
      int chunk_size = file_size > 512 ? 512 : file_size;
      int read_retval = read (file_fd, buf, chunk_size);
      int bytes_read = read_retval > 0 ? read_retval : 0;

      if (bytes_read != chunk_size && !read_error)
        {
          printf ("%s: read error\n", file_name);
          read_error = true;
          success = false;
        }

      memset (buf + bytes_read, 0, 512 - bytes_read);
      if (!do_write (archive_fd, buf, 512, write_error))
        success = false;

      file_size -= chunk_size;
    }

  return success;
}
Exemplo n.º 12
0
int file_send(char *name, struct xfer_callback *cbs)
{
    int len, flen, slen, total;
    char buf[1024] = {0};
    FILE *fp = fopen(name, "r");
    assert(fp);
    total = flen = filesize(fp);
    void *arg = cbs->xfer_client_init("127.0.0.1", 5555);

    sleep(1);
    while (flen > 0) {
        usleep(20 * 1000);
        len = fread(buf, 1, sizeof(buf), fp);
        if (len == -1) {
            printf("%s:%d xxxx\n", __func__, __LINE__);
            break;
        }
        slen = cbs->xfer_send(arg, buf, len);
        if (slen <= 0) {
            printf("xfer_send error: %d\n", cbs->xfer_errno(arg));
            break;
        }
        if (slen != len) {
            printf("%s:%d slen=%d, len=%d\n", __func__, __LINE__, slen, len);
        }
        flen -= len;
        printf("already sent %s file %dKB/%dKB = %02f%%\n", name, (total-flen), total, (total-flen)/(total*1.0)*100);
    }
    sleep(1);
    cbs->xfer_close(arg);
    fclose(fp);
    printf("file %s length is %u\n", name, flen);
    return total;
}
Exemplo n.º 13
0
vector<int> fImageSource(string filename, int &fileSize)
{
	vector<int> bitsOut;

	ifstream file;
	file.open((char *)filename.c_str());
	int bufferSize = filesize((char *)filename.c_str());
	fileSize = bufferSize;

	char * buffer = new char[bufferSize];

	// read file
	file.read(buffer, bufferSize);
	file.close();

	// decompose into single bits
	bitsOut.resize(bufferSize*8+2);
	bitsOut[0] = bitsOut[1] = 1; // add 2 pilot bits
	// see comment in fChannelEstimator
	for (int i = 0; i < bufferSize; i++)
	{
		char tmp = buffer[i];
		for (int j = 0; j < 8; j++)
		{
			if (tmp & (1 << (7-j))) bitsOut[i*8+2+j] = 1;
			else bitsOut[i*8+2+j] = 0;
		}
	}

	return bitsOut;
}
Exemplo n.º 14
0
static char *
newregfile(
	char		**pp,
	int		*len)
{
	char		*buf;
	int		fd;
	char		*fname;
	long		size;

	fname = getstr(pp);
	if ((fd = open(fname, O_RDONLY)) < 0 || (size = filesize(fd)) < 0) {
		fprintf(stderr, _("%s: cannot open %s: %s\n"),
			progname, fname, strerror(errno));
		exit(1);
	}
	if ((*len = (int)size)) {
		buf = malloc(size);
		if (read(fd, buf, size) < size) {
			fprintf(stderr, _("%s: read failed on %s: %s\n"),
				progname, fname, strerror(errno));
			exit(1);
		}
	} else
		buf = 0;
	close(fd);
	return buf;
}
Exemplo n.º 15
0
// returns -1 for error
int scLoadFile (LPCSTR psPathedFilename, void **bufferptr, bool bBinaryMode /* = true */)
{
	FILE	*f;
	int    length;
	void    *buffer;

	f = fopen(psPathedFilename,bBinaryMode?"rb":"rt");
	if (f)
	{
		length = filesize(f);	
		buffer = malloc (length+1);
		((char *)buffer)[length] = 0;
		int lread = fread (buffer,1,length, f);	
		fclose (f);

		if (lread==length)
		{	
			*bufferptr = buffer;
			return length;
		}
		free(buffer);
	}

	ErrorBox(va("Error reading file %s!",psPathedFilename));
	return -1;
}
Exemplo n.º 16
0
static int guess_size (char * filename, ren_vid_format_t colorspace, int * w, int * h)
{
	off_t size;

	if ((size = filesize (filename)) == -1) {
		return -1;
	}

	if (*w==-1 && *h==-1) {
		/* Image size unspecified */
		int nr_sizes = sizeof(sizes) / sizeof(sizes[0]);
		int i;

		for (i=0; i<nr_sizes; i++) {

			if (size == imgsize(colorspace, sizes[i].w, sizes[i].h)) {
				*w = sizes[i].w;
				*h = sizes[i].h;
				return 0;
			}
		}
	}

	return -1;
}
Exemplo n.º 17
0
/* Riduce il file f di len byte dalla posizione pos */
void shrink(FILE *f, ULONG pos, ULONG len)
{
#define BLOCK 65535
 char buf[BLOCK];
 ULONG start, end, tomove, blks;

 end = filesize(f);
 tomove = end-pos-len; /* byte da spostare */
 start = pos+len; /* posizione iniziale del blocco da spostare */

 for (blks=tomove/BLOCK; blks; start+=BLOCK,blks--)
 {
  fseek(f,start,SEEK_SET);
  fread(buf,1,BLOCK,f);
  fseek(f,start-len,SEEK_SET);
  fwrite(buf,1,BLOCK,f);
 }
 /* Sposta gli ultimi byte */
 tomove %= BLOCK;
 fseek(f,(long)-tomove,SEEK_END);
 fread(buf,1,tomove,f);
 fseek(f,(long)-(tomove+len),SEEK_END);
 fwrite(buf,1,tomove,f);
/* Come si imposta la fine di un file in modo ANSIsh??? */
 chsize(fileno(f),end-len);
}
Exemplo n.º 18
0
int config_read_fp(config_t* cfg, FILE *fp)
{
	int size, fd;

	size = filesize(cfg,fp);

	fd = fileno(fp);
	if (fd < 0) {
		config_set_strerror(cfg, "config_read_fp(): %s", strerror(errno));
		return -1;
	}

#if WIN32
        /* TODO: not supported on Windows */
        return 0;
#else
        void* mem;
	mem = mmap(0, size, PROT_READ, MAP_SHARED, fd, ftell(fp));
	if (mem == MAP_FAILED) {
		config_set_strerror(cfg, "config_read_fp(): %s", strerror(errno));
		return -1;
	}

	return config_read_mem(cfg, mem, size);
#endif
}
Exemplo n.º 19
0
int
main (int argc, char *argv[])
{
  int in_fd, out_fd;
  mapid_t in_map, out_map;
  void *in_data = (void *) 0x10000000;
  void *out_data = (void *) 0x20000000;
  int size;

  if (argc != 3)
    {
      printf ("usage: cp OLD NEW\n");
      return EXIT_FAILURE;
    }

  /* Open input file. */
  in_fd = open (argv[1]);
  if (in_fd < 0)
    {
      printf ("%s: open failed\n", argv[1]);
      return EXIT_FAILURE;
    }
  size = filesize (in_fd);

  /* Create and open output file. */
  if (!create (argv[2], size))
    {
      printf ("%s: create failed\n", argv[2]);
      return EXIT_FAILURE;
    }
  out_fd = open (argv[2]);
  if (out_fd < 0)
    {
      printf ("%s: open failed\n", argv[2]);
      return EXIT_FAILURE;
    }

  /* Map files. */
  in_map = mmap (in_fd, in_data);
  if (in_map == MAP_FAILED)
    {
      printf ("%s: mmap failed\n", argv[1]);
      return EXIT_FAILURE;
    }
  out_map = mmap (out_fd, out_data);
  if (out_map == MAP_FAILED)
    {
      printf ("%s: mmap failed\n", argv[2]);
      return EXIT_FAILURE;
    }

  /* Copy files. */
  memcpy (out_data, in_data, size);

  /* Unmap files (optional). */
  munmap (in_map);
  munmap (out_map);

  return EXIT_SUCCESS;
}
Exemplo n.º 20
0
void mod_info (flux_t h, opt_t opt)
{
    char *modpath = NULL;
    char *modname = NULL;
    char *digest = NULL;

    if (opt.argc != 1)
        usage ();
    if (strchr (opt.argv[0], '/')) {
        if (!(modpath = realpath (opt.argv[0], NULL)))
            oom ();
        if (!(modname = flux_modname (modpath)))
            msg_exit ("%s", dlerror ());
    } else {
        char *searchpath = getenv ("FLUX_MODULE_PATH");
        if (!searchpath)
            searchpath = MODULE_PATH;
        modname = xstrdup (opt.argv[0]);
        if (!(modpath = flux_modfind (searchpath, modname)))
            msg_exit ("%s: not found in module search path", modname);
    }
    digest = sha1 (modpath);
    printf ("Module name:  %s\n", modname);
    printf ("Module path:  %s\n", modpath);
    printf ("SHA1 Digest:  %s\n", digest);
    printf ("Size:         %d bytes\n", filesize (modpath));

    if (modpath)
        free (modpath);
    if (modname)
        free (modname);
    if (digest)
        free (digest);
}
Exemplo n.º 21
0
//-----------------------------------------------------------------------------
//
// M_ReadFile
//
unsigned int M_ReadFile (char const*name, byte**buffer)
{
  unsigned int length;
  byte *buf;
  FILE * handle;

  length = filesize (name);
  if (length)
  {
    handle = fopen (name, "rb");
    if (handle == NULL)
    {
      length = 0;
    }
    else
    {
      buf = Z_Malloc (length, PU_STATIC, NULL);
      length = fread (buf, 1, length, handle);
      fclose (handle);
      *buffer = buf;
    }
  }

  return (length);
}
Exemplo n.º 22
0
// returns -1 for error
int LoadFile (LPCSTR psPathedFilename, void **bufferptr)
{
	FILE	*f;
	int    length;
	void    *buffer;

	*bufferptr = 0;	// some code checks this as a return instead

	f = fopen(psPathedFilename,"rb");
	if (f)
	{
		length = filesize(f);	
		buffer = malloc (length+1 + 4096);	// keep this in sync with INPUT_BUF_SIZE, since the JPG loader is sloppy
		((char *)buffer)[length] = 0;
		int lread = fread (buffer,1,length, f);	
		fclose (f);

		if (lread==length)
		{	
			*bufferptr = buffer;
			return length;
		}
		free(buffer);
	}

	ErrorBox(va("Error reading file %s!",psPathedFilename));
	return -1;
}
Exemplo n.º 23
0
PySubStream* CachedObjectMgr::LoadCachedFile( const char* abs_fname, const char* oname )
{
    FILE* f = fopen( abs_fname, "rb" );

    if( f == NULL ) {
		sLog.Error("CachedObjMgr","Unable to open cache file '%s' for oname '%s': %s", abs_fname, oname, strerror( errno ) );
        return false;
    }

    uint64 file_length = filesize( f );
    if( file_length == 0 ) {
		sLog.Error("CachedObjMgr","Unable to stat cache file '%s' for oname '%s'", abs_fname, oname );

        fclose( f );
        return false;
    }

    Buffer* buf = new Buffer( file_length );

    if( file_length != fread( &( *buf )[0], sizeof( uint8 ), file_length, f ) ) {
		sLog.Error("CachedObjMgr","Unable to read cache file '%s' for oname '%s%': %s", abs_fname, oname, strerror( errno ) );

        SafeDelete( buf );
        fclose( f );
        return false;
    }

    fclose( f );

	sLog.Debug("CachedObjMgr","Loaded cache file for '%s': length %u", oname, file_length );

    return new PySubStream( new PyBuffer( &buf ) );
}
Exemplo n.º 24
0
double one_halo_from_file(double m)
{
  static double *x, *y, *z;
  static int n, flag = 1;
  FILE *fp;
  int i;
  double a;
  
  if(flag)
    {
      muh(0);
      fp = openfile("ncen.dat");
      muh(0);
      n = filesize(fp);
      x = dvector(1,n);
      y = dvector(1,n);
      z = dvector(1,n);
      for(i=1;i<=n;++i)
	fscanf(fp,"%lf %lf",&x[i],&y[i]);
      spline(x,y,n,1.0E+30,1.0E+30,z);
      flag = 0;
      muh(0);
    }
  if(log10(m)<x[1])return 0;
  splint(x,y,z,n,log10(m),&a);
  //printf("%e %e\n",m,pow(10.0,a));
  if(a>0) return 1;
  return pow(10.0,a);

}
Exemplo n.º 25
0
void initiate(char ** argv){
  int key2 = ftok("makefile",'e');
    //creating
  if (strcmp(argv[1], "--create") == 0){
    createsharedmem(key2);
    createsem(key2);
    createfile("story.txt");
    printf("INITIATED\n");
  }
  //removing
  else if (strcmp(argv[1], "--remove") == 0) {
    //remove the shared memory (we need to remove pointers to memories separately or else shared memory will not disappear)
    removesharedmem(key2);
    //remove the semaphore
    removesem(key2);
    //display the file
    if (filesize() >0){
      int fd;
      fd = open("story.txt", O_RDWR | O_APPEND, 0644);
      write(fd, "\n",2);
    }
    //Display the full contents of the story 
    execlp("cat","cat","story.txt",NULL);
  }
  else{
   printf("INVALID INPUT: Please run control with either '--create' or '--remove'.\n");//
  } 
}
Exemplo n.º 26
0
// returns -1 for error
int LoadFile (LPCSTR psPathedFilename, void **bufferptr, int bReportErrors)
{
	FILE	*f;
	int    length;
	void    *buffer;

	f = fopen(psPathedFilename,"rb");
	if (f)
	{
		length = filesize(f);	
		buffer = malloc (length+1);
		((char *)buffer)[length] = 0;
		int lread = fread (buffer,1,length, f);	
		fclose (f);

		if (lread==length)
		{	
			*bufferptr = buffer;
			return length;
		}
		free(buffer);
	}

	extern bool gbInImageLoader;	// tacky, but keeps quieter errors
	if (bReportErrors && !gbInImageLoader)
	{
		ErrorBox(va("Error reading file %s!",psPathedFilename));
	}
	return -1;
}
Exemplo n.º 27
0
/* Load raw binary image. */
int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size)
{
    int fd;
    int rc;
    int len;
    char filename[MAX_PATH];

    snprintf(filename,sizeof(filename),"%s",firmware);
    fd = open(filename, O_RDONLY);
    if(fd < 0)
    {
        return EFILE_NOT_FOUND;
    }

    len = filesize(fd);
    
    if (len > buffer_size)
        return EFILE_TOO_BIG;

    rc = read(fd, buf, len);
    if(rc < len)
        return EREAD_IMAGE_FAILED;

    close(fd);
    return len;
}
Exemplo n.º 28
0
bool get_smaf_metadata(int fd, struct mp3entry* id3)
{
    /* temporary buffer */
    unsigned char *tmp = (unsigned char *)id3->path;
    unsigned int chunksize;

    id3->title    = NULL;
    id3->artist   = NULL;
    id3->composer = NULL;

    id3->vbr      = false;   /* All SMAF files are CBR */
    id3->filesize = filesize(fd);

    /* check File Chunk and Contents Info Chunk */
    lseek(fd, 0, SEEK_SET);
    read(fd, tmp, 16);
    if ((memcmp(tmp, "MMMD", 4) != 0) || (memcmp(tmp + 8, "CNTI", 4) != 0))
    {
        DEBUGF("metadata error: does not smaf format\n");
        return false;
    }

    chunksize = get_long_be(tmp + 12);
    if (chunksize > 5)
        return parse_smaf_audio_track(fd, id3, chunksize);

    return parse_smaf_score_track(fd, id3);
}
Exemplo n.º 29
0
Arquivo: os.c Projeto: DinrusGroup/DRC
int os_file_exists(const char *name)
{
#if _WIN32
    DWORD dw;
    int result;

    dw = GetFileAttributes(name);
    if (dw == -1L)
        result = 0;
    else if (dw & FILE_ATTRIBUTE_DIRECTORY)
        result = 2;
    else
        result = 1;
    return result;
#elif DOS386
    struct FIND *find;

    find = findfirst(name,FA_DIREC | FA_SYSTEM | FA_HIDDEN);
    if (!find)
        return 0;
    return (find->attribute & FA_DIREC) ? 2 : 1;
#elif linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
    struct stat buf;

    return stat(name,&buf) == 0;        /* file exists if stat succeeded */

#else
    return filesize(name) != -1L;
#endif
}
Exemplo n.º 30
0
ReadMappingReader::ReadMappingReader(string file) : m_fp(NULL), m_file_name(file), m_total_to_read(0),
	m_total_read(0)
{
	if((m_fp = fopen(file.c_str(), "r")) == NULL)
		throw Bio::Bad_file(file, "Failed to open SAM file", __PRETTY_FUNCTION__);
	m_total_to_read = filesize(m_file_name.c_str());
}