File: misc.cc

package info (click to toggle)
id3ed 1.10.4-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 164 kB
  • ctags: 59
  • sloc: cpp: 646; sh: 153; makefile: 83
file content (41 lines) | stat: -rw-r--r-- 1,019 bytes parent folder | download | duplicates (3)
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
#include "misc.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>


int doread(int handle,void * buf,ssize_t len, const char * name){
   ssize_t i;
   if ((i=read(handle,buf,len))!=len){
      fprintf(stderr,"Error reading %s (%i/%i): %s\n",name,i,len,strerror(errno));
      return -1;
   }
   return 0;
}
int dowrite(int handle, const void * buf, ssize_t len,const char *name,const char *name2){
   ssize_t i;
   if ((i=write(handle,buf,len))!=len){
      fprintf(stderr,"Error writing %s %s (%i/%i): %s\n",name,name2,i,len,strerror(errno));
      return -1;
   }
   else return 0;
}
int doopen(int &handle,const char * name,int access,int mode) {
   if ((handle=open(name,access,mode))==-1){
      fprintf(stderr,"Error opening %s: %s\n",name,strerror(errno));
      return -1;
   }
   else return 0;
}
#ifndef HAVE_STRERROR
const char * strerror(int err){
	static char buf[5];
#ifdef HAVE_SNPRINTF
	snprintf(buf,5,"%i",err);
#else
	sprintf(buf,"%i",err);
#endif
	return buf;
}
#endif