File: fileinput.cc

package info (click to toggle)
splay 0.9.5.2-13
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 756 kB
  • ctags: 1,167
  • sloc: cpp: 7,680; sh: 330; makefile: 83
file content (93 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* MPEG Sound library

   (C) 1997 by Woo-jae Jung */

// Binput.cc
// Inputstream from file

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <sys/stat.h>
#include <unistd.h>

#include "mpegsound.h"

/************************/
/* Input bitstrem class */
/************************/
Soundinputstreamfromfile::~Soundinputstreamfromfile()
{
  if(fp)fclose(fp);
}

bool Soundinputstreamfromfile::open(char *filename)
{
  struct stat buf;

  if(filename==NULL)
  {
    fp=stdin;
    size=0;
    return true;
  }
  else if((fp=fopen(filename,"r"))==NULL)
  {
    seterrorcode(SOUND_ERROR_FILEOPENFAIL);
    return false;
  }

  stat(filename,&buf);
  size=buf.st_size;

  return true;
}

int Soundinputstreamfromfile::getbytedirect(void)
{
  int c;

  if((c=getc(fp))<0)
    seterrorcode(SOUND_ERROR_FILEREADFAIL);

  return c;
}

bool Soundinputstreamfromfile::_readbuffer(char *buffer,int size)
{
  if(fread(buffer,size,1,fp)!=1)
  {
    seterrorcode(SOUND_ERROR_FILEREADFAIL);
    return false;
  }
  return true;
}

bool Soundinputstreamfromfile::eof(void)
{
  return feof(fp);
};

int Soundinputstreamfromfile::getblock(char *buffer,int size)
{
  return fread(buffer,1,size,fp);
}

int Soundinputstreamfromfile::getsize(void)
{
  return size;
}

void Soundinputstreamfromfile::setposition(int pos)
{
  if(fp==stdin)return;
  fseek(fp,pos,SEEK_SET);
}

int  Soundinputstreamfromfile::getposition(void)
{
  if(fp==stdin)return 0;
  return ftell(fp);
}