示例#1
0
文件: wrapper.c 项目: AllardJ/Tomato
int creat64(const char *path, mode_t mode)
{
	extern int creat_bits;
        
        check_init("creat64");
	return openx((char *) path, creat_bits, mode, smbw_libc.open64);
}
示例#2
0
文件: wrapper.c 项目: AllardJ/Tomato
int open64 (__const char *name, int flags, ...)
{
        va_list ap;
        mode_t mode;
        
        va_start(ap, flags);
        mode = va_arg(ap, mode_t);
        va_end(ap);
        
        check_init("open64");
        return openx((char *) name, flags, mode, smbw_libc.open64);
}
示例#3
0
文件: mrcrc.c 项目: jorzchyk/mrcrc
int main(int argc, char** argv)
{
	int i;

	if(argc < 4)
		errx(-1, "missing arguments");

	int nproc = atoi(argv[1]);
	char* inputname = argv[2];
	char* outputname = argv[3];

	int inputfd = openx(inputname, O_RDONLY);
	int outputfd = openx(outputname, O_RDWR | O_CREAT);

	off_t inputsize = argc > 4 ? parsesize(argv[4]) : statfdsize(inputfd, inputname);
	off_t outputsize = DISTINCT_CRC_VALUES * sizeof(count_t);

	uint8_t* input = mapinput(inputfd, inputsize, inputname);
	count_t* output = mapoutput(outputfd, outputsize, outputname);
	
	pid_t children[nproc];
	pid_t dead;

	for(i = 0; i < nproc; i++)
		if((children[i] = spawnworker(i, nproc, input, inputsize, output)) < 0)
			break;

	int status;
	while(notempty(children, nproc))
		if((dead = wait(&status)) > 0)
			if(handledead(children, nproc, dead, status))
				break;

	terminate(children, nproc);
	return messy(children, nproc) ? -1 : 0;
}
void
scsi_name(char *name)
{
	char *cp;

	if (!name) {
		name = getenv("TAPE");
		if (name == NULL)
			fatal("Missing environment name TAPE\n");
	}
	while (*name == '+')
		++name;

	hdev = openx(name, O_RDWR, 0, SC_DIAGNOSTIC);
	if (hdev < 0)
		fatal("Cannot access device %s", name);

	if ((cp = getenv("TAPEMODE")) != NULL)
		senseMode = atoi(cp);
}
示例#5
0
文件: wrapper.c 项目: AllardJ/Tomato
int __open64(char *name, int flags, mode_t mode)
{
        check_init("__open64");
        return openx(name, flags, mode, smbw_libc.__open64);
}
示例#6
0
文件: wrapper.c 项目: AllardJ/Tomato
int _open(char *name, int flags, mode_t mode)
{
        check_init("open");
        
        return openx(name, flags, mode, smbw_libc._open);
}
示例#7
0
int SCSI_OpenDevice(int ip)
{
  int DeviceFD;
  int i;
  extern OpenFiles_T *pDev;
  
  if (pDev[ip].inqdone == 0)
    {
      pDev[ip].inqdone = 1;
      /*
       * Check if it is an gsc (generic SCSI device)
       */
      if (strncmp("/dev/gsc", pDev[ip].dev, 8) == 0)
        {
	  pDev[ip].flags = AIX_USE_GSC;
          DeviceFD = open(pDev[ip].dev, 0);
        } else {
          DeviceFD = openx(pDev[ip].dev, O_RDWR, 0, SC_DIAGNOSTIC);
        }
      if (DeviceFD >= 0)
	{
	  pDev[ip].avail = 1;
          pDev[ip].fd = DeviceFD;
          pDev[ip].SCSI = 0;
          pDev[ip].devopen = 1;
          pDev[ip].inquiry = (SCSIInquiry_T *)malloc(INQUIRY_SIZE);

          if (SCSI_Inquiry(ip, pDev[ip].inquiry, INQUIRY_SIZE) == 0)
	    {
             if (pDev[ip].inquiry->type == TYPE_TAPE || pDev[ip].inquiry->type == TYPE_CHANGER)
               {
                 for (i=0;i < 16;i++)
                   pDev[ip].ident[i] = pDev[ip].inquiry->prod_ident[i];
                 for (i=15; i >= 0 && !isalnum(pDev[ip].ident[i]) ; i--)
                   {
                     pDev[ip].ident[i] = '\0';
                   }
                 pDev[ip].SCSI = 1;

		  if (pDev[ip].inquiry->type == TYPE_TAPE)
		  {
		          pDev[ip].type = stralloc("tape");
		  }

		  if (pDev[ip].inquiry->type == TYPE_CHANGER)
		  {
		          pDev[ip].type = stralloc("changer");
		  }

                 PrintInquiry(pDev[ip].inquiry);
                 return(1); 
               } else {
                 close(DeviceFD);
                 free(pDev[ip].inquiry);
                 return(0);
               }
           }
           free(pDev[ip].inquiry);
           pDev[ip].inquiry = NULL;
           return(1);
       } else {
	 dbprintf(_("SCSI_OpenDevice %s failed\n"), pDev[ip].dev);
         return(0);
       }
    } else {
      if ((DeviceFD = openx(pDev[ip].dev, O_RDWR, 0, SC_DIAGNOSTIC)) >= 0)
        {
          pDev[ip].fd = DeviceFD;
          pDev[ip].devopen = 1;
          return(1);
        }
    }
  return(0);
}
示例#8
0
文件: FREPL.C 项目: Execsl/usnap
int main(int argc, char **argv) {
  int i, count = 0, self = FALSE;
  FILE *f, *fo;

  if (argc >= 2) {
    if ((argv[1][0] == '-') || (argv[1][0] == '/')) {
      if (strchr(argv[1], '?') != NULL) {
	about();
	return 0;
      }
      if (strchr(argv[1], 's') != NULL) { silent = TRUE; }
      if (strchr(argv[1], 'i') != NULL) { ignorecase = TRUE; }
      if (strchr(argv[1], 'm') != NULL) { self = TRUE; }
      argv[1] = argv[0];
      argv++;
      argc--;
    }
  }
  if (argc < 4) {
    fprintf(stderr, "frepl [-?sim] <src> <dest> <infile> [<outfile>]\n");
    return 1;
  } else {
    if ((self == TRUE) || (argc >= 5)) {
      if ((fo = openx(0)) == NULL) {
	perror("error in opening temp file FREPLTMP.$$$");
	return 10;
      }
    } else { fo = stdout; }
  }

  makestr(argv[1], s);
  makestr(argv[2], d);
  if (silent == FALSE) { fprintf(stderr, "Source string = \"%s\"\nDest string = \"%s\"\n", s, d); }

  if ((f = fopenx(argv[3], "rb")) == NULL) {
    if (silent == FALSE) { perror("error in opening source file"); }
    return 2;
  }

  for (;;) {
    if ((i = fgetc(f)) == EOF) {
      break;
    }
    if (charequal((char)i, s[0]) == TRUE) {	/* 1st matched */
      if (rmatch(f, s + 1) == TRUE) {
	if (silent == FALSE) { fprintf(stderr, "\rCount = %04d   ", ++count); }
	fputs(d, fo);
      } else {
	fputc(i, fo);
      }
    } else {
      fputc(i, fo);
    }
  }
  fclose(f);
  fclose(fo);

  if (silent == FALSE) { fprintf(stderr, "\n"); }

  if ((self == TRUE) || (argc >= 5)) {
    if ((f = openx(1)) == NULL) {
      if (silent == FALSE) { perror("error in preparing to read temp file FREPLTMP.$$$"); }
      return 21;
    }
    if (silent == FALSE) { fprintf(stderr, "rewrite file...\n"); }
    if (self == TRUE) { copyto(f, argv[3], TRUE, "error in preparing to write infile"); }
    if (argc >= 5) { copyto(f, argv[4], FALSE, "error in preparing to write outfile"); }
    fclose(f);
    if (silent == FALSE) { fprintf(stderr, "deleting temp file...\n"); }
    remove("FREPLTMP.$$$");
  }

  return 0;
}
示例#9
0
static int SDL_SYS_CDOpen(int drive)
{
    int   fd;
    char* lastsl;
    char* cdromname;

    /*
     * We found /dev/cd? drives and that is in our list. But we can
     * open only the /dev/rcd? versions of those devices for Audio CD.
     */
    cdromname = (char*)malloc( strlen(SDL_cdlist[drive]+2) );
    strcpy(cdromname,SDL_cdlist[drive]);
    lastsl = strrchr(cdromname,'/');
    if (lastsl) {
	*lastsl = 0;
	strcat(cdromname,"/r");
	lastsl = strrchr(SDL_cdlist[drive],'/');
	if (lastsl) {
	    lastsl++;
	    strcat(cdromname,lastsl);
	}
    }

#ifdef DEBUG_CDROM
    fprintf(stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive], cdromname);
#endif

    /*
     * Use exclusive access. Don't use SC_DIAGNOSTICS as xmcd does because they
     * require root priviledges, and we don't want that. SC_SINGLE provides
     * exclusive access with less trouble.
     */
    fd = openx(cdromname, O_RDONLY, NULL, SC_SINGLE);
    if ( fd < 0 )
    {
#ifdef DEBUG_CDROM
            fprintf(stderr, "Could not open drive %s (%s)\n", cdromname, strerror(errno));
#endif
    }
    else
    {
	struct mode_form_op cdMode;
	int                 ret;
#ifdef DEBUG_CDROM
	cdMode.action = CD_GET_MODE;
	ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode);
	if ( ret < 0 ) {
            fprintf(stderr,
	            "Could not get drive mode for %s (%s)\n",
		    cdromname, strerror(errno));
	} else {
	    switch(cdMode.cd_mode_form) {
		case CD_MODE1 :
                    fprintf(stderr,
	                "Drive mode for %s is %s\n",
		        cdromname, "CD-ROM Data Mode 1");
		    break;
		case CD_MODE2_FORM1 :
                    fprintf(stderr,
	                "Drive mode for %s is %s\n",
		        cdromname, "CD-ROM XA Data Mode 2 Form 1");
		    break;
		case CD_MODE2_FORM2 :
                    fprintf(stderr,
	                "Drive mode for %s is %s\n",
		        cdromname, "CD-ROM XA Data Mode 2 Form 2");
		    break;
		case CD_DA :
                    fprintf(stderr,
	                "Drive mode for %s is %s\n",
		        cdromname, "CD-DA");
		    break;
		default :
                    fprintf(stderr,
	                "Drive mode for %s is %s\n",
		        cdromname, "unknown");
		    break;
	    }
	}
#endif

	cdMode.action       = CD_CHG_MODE;
	cdMode.cd_mode_form = CD_DA;
	ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode);
	if ( ret < 0 ) {
#ifdef DEBUG_CDROM
            fprintf(stderr,
	            "Could not set drive mode for %s (%s)\n",
		    cdromname, strerror(errno));
#endif
            SDL_SetError("ioctl() error: Could not set CD drive mode, %s",
	                 strerror(errno));
	} else {
#ifdef DEBUG_CDROM
            fprintf(stderr,
	            "Drive mode for %s set to CD_DA\n",
		    cdromname);
#endif
	}
    }
    free(cdromname);
    return fd;
}