Ejemplo n.º 1
0
USHORT TUser::Previous ()
{
   USHORT RetVal = FALSE;

   if (fdDat == -1)
      fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
   if (fdIdx == -1)
      fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);

   if (fdDat != -1 && fdIdx != -1 && (tell (fdIdx) - sizeof (Idx)) >= sizeof (Idx)) {
      do {
         lseek (fdIdx, tell (fdIdx) - sizeof (Idx) * 2, SEEK_SET);
         if (read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) {
            if (Idx.Deleted == FALSE)
               RetVal = TRUE;
         }
      } while (RetVal == FALSE && tell (fdIdx) >= sizeof (Idx) * 2);

      if (RetVal == TRUE) {
         Clear ();
         lseek (fdDat, Idx.Position, SEEK_SET);
         read (fdDat, &Usr, sizeof (Usr));
         Struct2Class ();
      }
   }

   return (RetVal);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	/* check args */

	if (argc != 4)
	{
		fprintf(stderr, "usage: %s header.asm prog1.bfjoust prog2.bfjoust\n", argv[0]);
		return 1;
	}

	/* parse competitors */

	int fdA = sopen(argv[2]), fdB = sopen(argv[3]);

	if (setjmp(fail_buf))
	{
		printf("parse error: %s\n", fail_msg);
		return 1;
	}

	struct oplist *opsA = parse(fdA), *opsB = parse(fdB);

	/* find maximum depth of nested repeats */

	int maxrepdepth;

	{
		int d1 = repdepth(opsA), d2 = repdepth(opsB);
		maxrepdepth = d1 > d2 ? d1 : d2;
	}

	printf("%%define MAXREPS %d\n\n", maxrepdepth);

	/* copy header */

	FILE *hdr = fopen(argv[1], "r");
	if (!hdr)
		die("open failed: %s", argv[1]);

	static unsigned char buf[4096];
	ssize_t got;

	while ((got = fread(buf, 1, sizeof buf, hdr)) > 0)
		fwrite(buf, 1, got, stdout);

	if (got < 0)
		die("read error");

	fclose(hdr);

	/* translate into code */

	compile(stdout, opsA, 'A', "pa", 0);
	compile(stdout, opsB, 'B', "pb", 0);
	compile(stdout, opsB, 'B', "pf", 1);

	opl_free(opsA);
	opl_free(opsB);
	return 0;
}
Ejemplo n.º 3
0
USHORT TUser::Add ()
{
   USHORT RetVal = FALSE;

   if (fdDat == -1)
      fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
   if (fdIdx == -1)
      fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);

   if (fdDat != -1 && fdIdx != -1) {
      lseek (fdDat, 0L, SEEK_END);
      lseek (fdIdx, 0L, SEEK_END);

      memset (&Idx, 0, sizeof (Idx));
      Idx.Deleted = FALSE;
      Idx.NameCrc = StringCrc32 (Name, 0xFFFFFFFFL);
      Idx.RealNameCrc = StringCrc32 (RealName, 0xFFFFFFFFL);
      Idx.Position = tell (fdDat);

      CurrentCRC = Idx.NameCrc;
      Class2Struct ();

      write (fdDat, &Usr, sizeof (Usr));
      write (fdIdx, &Idx, sizeof (Idx));

      MsgTag->UserId = Idx.NameCrc;
      MsgTag->Load ();
      FileTag->UserId = Idx.NameCrc;
      FileTag->Load ();

      RetVal = TRUE;
   }

   return (RetVal);
}
Ejemplo n.º 4
0
USHORT TFileBase::Open (PSZ pszDataPath, PSZ pszArea)
{
   CHAR szFile[128];

   strcpy (DataPath, pszDataPath);
   if (DataPath[0] != '\0') {
#if defined(__LINUX__)
      if (DataPath[strlen (DataPath) - 1] != '/')
         strcat (DataPath, "/");
#else
      if (DataPath[strlen (DataPath) - 1] != '\\')
         strcat (DataPath, "\\");
#endif
   }

   sprintf (szFile, "%s%s", DataPath, "filebase.idx");
   if ((fdIdx = sopen (AdjustPath (szFile), O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE)) == -1)
      return (FALSE);

   sprintf (szFile, "%s%s", DataPath, "filebase.dat");
   if ((fdDat = sopen (AdjustPath (szFile), O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE)) == -1) {
      close (fdDat);
      fdDat = -1;
      return (FALSE);
   }

   strcpy (szArea, pszArea);

   return (TRUE);
}
Ejemplo n.º 5
0
void CLayout::CSizeGripper::DrawShadowLine(CDC *pdc, CPoint start, CPoint end)
{
    {
        CPen lightPen(PS_SOLID, 1, ::GetSysColor(COLOR_3DHIGHLIGHT));
        CSelectObject sopen(pdc, &lightPen);

        pdc->MoveTo(start);
        pdc->LineTo(end);
    }

    start.x++;
    end.y++;

    {
        CPen darkPen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
        CSelectObject sopen(pdc, &darkPen);

        pdc->MoveTo(start);
        pdc->LineTo(end);

        start.x++;
        end.y++;

        pdc->MoveTo(start);
        pdc->LineTo(end);
    }
}
Ejemplo n.º 6
0
BOOL DLLCALL removefiledat(scfg_t* cfg, file_t* f)
{
	char	c,str[MAX_PATH+1],ixbname[12],*ixbbuf,fname[13];
    int		i,file;
	long	l,length;

	SAFECOPY(fname,f->name);
	for(i=8;i<12;i++)   /* Turn FILENAME.EXT into FILENAMEEXT */
		fname[i]=fname[i+1];
	SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
	if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) {
		return(FALSE); 
	}
	length=(long)filelength(file);
	if(!length) {
		close(file);
		return(FALSE); 
	}
	if((ixbbuf=(char *)malloc(length))==0) {
		close(file);
		return(FALSE); 
	}
	if(lread(file,ixbbuf,length)!=length) {
		close(file);
		free((char *)ixbbuf);
		return(FALSE); 
	}
	close(file);
	if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) {
		return(FALSE); 
	}
	for(l=0;l<length;l+=F_IXBSIZE) {
		for(i=0;i<11;i++)
			ixbname[i]=ixbbuf[l+i];
		ixbname[i]=0;
		if(stricmp(ixbname,fname))
			if(lwrite(file,&ixbbuf[l],F_IXBSIZE)!=F_IXBSIZE) {
				close(file);
				free((char *)ixbbuf);
				return(FALSE); 
		} 
	}
	free((char *)ixbbuf);
	close(file);
	SAFEPRINTF2(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
	if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) {
		return(FALSE); 
	}
	lseek(file,f->datoffset,SEEK_SET);
	c=ETX;          /* If first char of record is ETX, record is unused */
	if(write(file,&c,1)!=1) { /* So write a D_T on the first byte of the record */
		close(file);
		return(FALSE); 
	}
	close(file);
	if(f->dir==cfg->user_dir)  /* remove file from index */
		rmuserxfers(cfg,0,0,f->name);
	return(TRUE);
}
Ejemplo n.º 7
0
USHORT TUser::GetData (PSZ pszName, USHORT fCheckRealName)
{
   USHORT RetVal = FALSE, DoClose = FALSE;
   ULONG TestCrc;

   if (fdDat == -1) {
      fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
      DoClose = TRUE;
   }
   if (fdIdx == -1) {
      fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
      DoClose = TRUE;
   }

   if (fdDat != -1 && fdIdx != -1) {
      Clear ();

      TestCrc = StringCrc32 (pszName, 0xFFFFFFFFL);

      lseek (fdIdx, 0L, SEEK_SET);
      while (RetVal == FALSE && read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) {
         if (Idx.Deleted == FALSE && Idx.NameCrc == TestCrc)
            RetVal = TRUE;
      }
      if (RetVal == FALSE && fCheckRealName == TRUE) {
         lseek (fdIdx, 0L, SEEK_SET);
         while (RetVal == FALSE && read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) {
            if (Idx.Deleted == FALSE && Idx.RealNameCrc == TestCrc)
               RetVal = TRUE;
         }
      }
      if (RetVal == TRUE) {
         lseek (fdDat, Idx.Position, SEEK_SET);
         read (fdDat, &Usr, sizeof (Usr));

         Struct2Class ();

         MsgTag->UserId = Idx.NameCrc;
         MsgTag->Load ();
         FileTag->UserId = Idx.NameCrc;
         FileTag->Load ();
      }
   }

   if (DoClose == TRUE) {
      if (fdDat != -1) {
         close (fdDat);
         fdDat = -1;
      }
      if (fdIdx != -1) {
         close (fdIdx);
         fdIdx = -1;
      }
   }

   return (RetVal);
}
Ejemplo n.º 8
0
VOID TUser::Pack ()
{
   int fdNew;

   if (fdDat == -1)
      fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
   if (fdIdx == -1)
      fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);

   fdNew = sopen ("users.new", O_RDWR|O_BINARY|O_CREAT|O_TRUNC, SH_DENYNO, S_IREAD|S_IWRITE);

   if (fdNew != -1 && fdDat != -1 && fdIdx != -1) {
      lseek (fdIdx, 0L, SEEK_SET);
      lseek (fdDat, 0L, SEEK_SET);

      while (read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) {
         if (Idx.Deleted == FALSE) {
            lseek (fdDat, Idx.Position, SEEK_SET);
            read (fdDat, &Usr, sizeof (Usr));
            write (fdNew, &Usr, sizeof (Usr));
         }
      }

      lseek (fdIdx, 0L, SEEK_SET);
      lseek (fdDat, 0L, SEEK_SET);
      lseek (fdNew, 0L, SEEK_SET);

      while (read (fdNew, &Usr, sizeof (Usr)) == sizeof (Usr)) {
         memset (&Idx, 0, sizeof (Idx));
         Idx.Deleted = FALSE;
         Idx.NameCrc = StringCrc32 (Usr.Name, 0xFFFFFFFFL);
         Idx.RealNameCrc = StringCrc32 (Usr.RealName, 0xFFFFFFFFL);
         Idx.Position = tell (fdDat);

         write (fdDat, &Usr, sizeof (Usr));
         write (fdIdx, &Idx, sizeof (Idx));
      }

      chsize (fdDat, tell (fdDat));
      chsize (fdIdx, tell (fdIdx));
   }

   if (fdNew != -1) {
      close (fdNew);
      unlink ("users.new");
   }

   if (fdIdx != -1) {
      close (fdIdx);
      fdIdx = -1;
   }
   if (fdDat != -1) {
      close (fdDat);
      fdDat = -1;
   }
}
Ejemplo n.º 9
0
static void sopen_test_thread(void* arg)
{
	int fd;

	if((fd=sopen(LOCK_FNAME,O_RDWR,SH_DENYWR))!=-1)
		printf("!FAILURE: allowed to reopen with SH_DENYWR\n");
	else if((fd=sopen(LOCK_FNAME,O_RDWR,SH_DENYRW))!=-1)
		printf("!FAILURE: allowed to reopen with SH_DENYRW\n");
	else
		printf("reopen disallowed\n");

	if(fd!=-1)
		close(fd);
}
Ejemplo n.º 10
0
VOID TProtocol::Delete ()
{
   int fdNew;
   USHORT DoClose = FALSE;
   ULONG Position;

   if (fdDat == -1) {
      fdDat = sopen (DataFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
      DoClose = TRUE;
   }

   fdNew = sopen ("temp.dat", O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);

   if (fdDat != -1 && fdNew != -1) {
      if ((Position = tell (fdDat)) > 0L)
         Position -= sizeof (PROTOCOL);

      lseek (fdDat, 0L, SEEK_SET);

      while (read (fdDat, &prot, sizeof (PROTOCOL)) == sizeof (PROTOCOL)) {
         if (strcmp (Key, prot.Key))
            write (fdNew, &prot, sizeof (PROTOCOL));
      }

      lseek (fdDat, 0L, SEEK_SET);
      lseek (fdNew, 0L, SEEK_SET);

      while (read (fdNew, &prot, sizeof (PROTOCOL)) == sizeof (PROTOCOL))
            write (fdDat, &prot, sizeof (PROTOCOL));

      chsize (fdDat, tell (fdDat));

      lseek (fdDat, Position, SEEK_SET);
      if (Next () == FALSE) {
         if (Previous () == FALSE)
            New ();
      }
   }

   if (fdNew != -1) {
      close (fdNew);
      unlink ("temp.dat");
   }
   if (fdDat != -1 && DoClose == TRUE) {
      close (fdDat);
      fdDat = -1;
   }
}
Ejemplo n.º 11
0
void open_gamedab()
{
if((gamedab=sopen("game.dab",O_RDWR|O_BINARY,SH_DENYNO))==-1) {
    bputs("Error opening game.dab\r\n");                /* open deny none */
    pause();
	exit(1); }
}
Ejemplo n.º 12
0
void CXySlider::PaintGripper(CDC *pdc)
{
    CRect rc = GetGripperRect();

    COLORREF color = ::GetSysColor(COLOR_BTNFACE);
    if(m_gripperHighlight)
    {
        int r = RGB_GET_RVALUE(color);
        int g = RGB_GET_GVALUE(color);
        int b = RGB_GET_BVALUE(color);
        r += (255 - r)/3;
        g += (255 - g)/3;
        b += (255 - b)/3;
        color = RGB(r, g, b);
    }
    pdc->FillSolidRect(rc, color);
    pdc->DrawEdge(rc, EDGE_RAISED, BF_RECT);

    CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
    CSelectObject sopen(pdc, &pen);

    pdc->MoveTo(rc.left, rc.top + rc.Height() / 2);
    pdc->LineTo(rc.right, rc.top + rc.Height() / 2);
    pdc->MoveTo(rc.left + rc.Width() / 2, rc.top);
    pdc->LineTo(rc.left + rc.Width() / 2, rc.bottom);
}
Ejemplo n.º 13
0
void CXySlider::PaintBackground(CDC *pdc)
{
    pdc->FillSolidRect(m_rcAll, ::GetSysColor(COLOR_BTNFACE));

    CRect rc = m_rcInner;
    pdc->DrawEdge(rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST);

    pdc->FillSolidRect(rc, RGB(255,255,255));

    CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DLIGHT));
    CSelectObject sopen(pdc, &pen);

    pdc->MoveTo(rc.left, m_zero.y);
    pdc->LineTo(rc.right, m_zero.y);
    pdc->MoveTo(m_zero.x, rc.top);
    pdc->LineTo(m_zero.x, rc.bottom);

    CRect circle = m_rcAll;
    circle.DeflateRect(m_gripperRadius);

    CSelectStockObject sobrush(pdc, NULL_BRUSH);
    pdc->Ellipse(circle);

    if(GetFocus() == this)
    {
        pdc->DrawFocusRect(m_rcAll);
    }
}
Ejemplo n.º 14
0
int main(void)
{
   FILE *fout;
   int i, fserial;


   fout = fopen("rom56.bin", "w");
   if (fout == NULL)
   {
      fprintf(stderr, "can't open rom56.bin for writing\n");
      exit(1);
   }
   fserial = sopen("/dev/ttyS0", B19200);
   if (fserial == -1)
   {
      fprintf(stderr, "can't open serial port\n");
      exit(1);
   }

   for (i=0; i<0x1000; i++)
   {
      fputc(sgetc(fserial), fout);
      printf(".");
   }

   fclose(fout);
   sclose(fserial);

   return 0;
}
Ejemplo n.º 15
0
VOID FIDOSDM::SetHWM (ULONG ulMsg)
{
   int fd;
   CHAR Temp[128];
   struct dosdate_t d_date;
   struct dostime_t d_time;
   FIDOMSG Hdr;

   sprintf (Temp, "%s1.msg", BasePath);
   if ((fd = sopen (Temp, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
      memset (&Hdr, 0, sizeof (FIDOMSG));
      strcpy (Hdr.From, "MsgBase");
      strcpy (Hdr.To, "Nobody in particular");
      strcpy (Hdr.Subject, "Re: Whatsa high water mark?");
      _dos_getdate (&d_date);
      _dos_gettime (&d_time);
      sprintf (Hdr.Date, "%2d %3.3s %02d  %02d:%02d:%02d", d_date.day, fidoMonths[d_date.month - 1], d_date.year % 100, d_time.hour, d_time.minute, d_time.second);
      Hdr.Up = (USHORT)ulMsg;
      Hdr.Attrib = MSGPRIVATE|MSGSENT|MSGREAD;
      write (fd, &Hdr, sizeof (FIDOMSG));
      strcpy (Temp, "\r\nThis message is used to store the high water mark\r\n");
      write (fd, Temp, strlen (Temp) + 1);
      close (fd);
   }
}
Ejemplo n.º 16
0
VOID TFileTag::Change (PSZ pszOldName, PSZ pszNewName)
{
   int fd, i, Count, Changed;
   ULONG Position;
   FILETAGS *Buffer;

   if ((fd = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
      if ((Buffer = (FILETAGS *)malloc (sizeof (FILETAGS) * FILETAGS_INDEX)) != NULL) {
         do {
            Changed = FALSE;

            Position = tell (fd);
            Count = read (fd, Buffer, sizeof (FILETAGS) * FILETAGS_INDEX) / sizeof (FILETAGS);
            for (i = 0; i < Count; i++) {
               if (Buffer[i].Free == FALSE && !stricmp (Buffer[i].Area, pszOldName)) {
                  strcpy (Buffer[i].Area, pszNewName);
                  Changed = TRUE;
               }
            }

            if (Changed == TRUE) {
               lseek (fd, Position, SEEK_SET);
               write (fd, Buffer, sizeof (FILETAGS) * Count);
            }
         } while (Count == FILETAGS_INDEX);
         free (Buffer);
      }

      close (fd);
   }
}
Ejemplo n.º 17
0
USHORT TProtocol::Read (PSZ key)
{
   USHORT RetVal = FALSE, DoClose = FALSE;

   if (fdDat == -1) {
      fdDat = sopen (DataFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
      DoClose = TRUE;
   }

   if (fdDat != -1) {
      lseek (fdDat, 0L, SEEK_SET);
      while (read (fdDat, &prot, sizeof (PROTOCOL)) == sizeof (PROTOCOL)) {
         if (!stricmp (key, prot.Key)) {
            Struct2Class (&prot);
            RetVal = TRUE;
            break;
         }
      }
   }

   if (fdDat != -1 && DoClose == TRUE) {
      close (fdDat);
      fdDat = -1;
   }

   return (RetVal);
}
Ejemplo n.º 18
0
extern "C" BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text, char* host, SOCKADDR_IN* addr)
{
	char	hdr[1024];
	char	tstr[64];
	char	fname[MAX_PATH+1];
	int		file;
	time32_t now=time32(NULL);

	sprintf(fname,"%shack.log",cfg->logs_dir);

	if((file=sopen(fname,O_CREAT|O_RDWR|O_BINARY|O_APPEND,SH_DENYWR,DEFFILEMODE))==-1)
		return(FALSE);

	sprintf(hdr,"SUSPECTED %s HACK ATTEMPT for user '%s' on %.24s\r\nUsing port %u at %s [%s]\r\nDetails: "
		,prot
		,user
		,timestr(cfg,now,tstr)
		,addr->sin_port
		,host
		,inet_ntoa(addr->sin_addr)
		);
	write(file,hdr,strlen(hdr));
	write(file,text,strlen(text));
	write(file,crlf,2);
	write(file,crlf,2);
	close(file);

	return(TRUE);
}
Ejemplo n.º 19
0
void CLog::initlog()
{
  logfile=sopen(g->v.log,O_WRONLY|O_APPEND|O_CREAT|O_TEXT,SH_DENYWR,S_IREAD|S_IWRITE);
  if (logfile==-1)
    throw errors("Unable to open log file "+g->v.log);
  write(logfile,"\r\n",2);
}
Ejemplo n.º 20
0
// Cambia l'ID dell'utente associato ai record.
// -----------------------------------------------------------------------------
VOID TMsgTag::Change (ULONG OldId, ULONG NewId)
{
   int fd, i, Count, Changed;
   ULONG Position;
   MSGTAGS *Buffer;

   if ((fd = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
      if ((Buffer = (MSGTAGS *)malloc (sizeof (MSGTAGS) * MSGTAGS_INDEX)) != NULL) {
         do {
            Changed = FALSE;

            Position = tell (fd);
            Count = read (fd, Buffer, sizeof (MSGTAGS) * MSGTAGS_INDEX) / sizeof (MSGTAGS);
            for (i = 0; i < Count; i++) {
               if (Buffer[i].Free == FALSE && Buffer[i].UserId == OldId) {
                  Buffer[i].UserId = NewId;
                  Changed = TRUE;
               }
            }

            if (Changed == TRUE) {
               lseek (fd, Position, SEEK_SET);
               write (fd, Buffer, sizeof (MSGTAGS) * Count);
            }
         } while (Count == MSGTAGS_INDEX);
         free (Buffer);
      }

      close (fd);
   }
}
Ejemplo n.º 21
0
File my_create(const char *FileName, int CreateFlags, int access_flags,
	       myf MyFlags)
{
  int fd;
  DBUG_ENTER("my_create");
  DBUG_PRINT("my",("Name: '%s' CreateFlags: %d  AccessFlags: %d  MyFlags: %d",
		   FileName, CreateFlags, access_flags, MyFlags));

#if !defined(NO_OPEN_3) && !defined(__EMX__)
  fd = open((my_string) FileName, access_flags | O_CREAT,
	    CreateFlags ? CreateFlags : my_umask);
#elif defined(VMS)
  fd = open((my_string) FileName, access_flags | O_CREAT, 0,
	    "ctx=stm","ctx=bin");
#elif defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2)
  if (access_flags & O_SHARE)
    fd = sopen((my_string) FileName, access_flags | O_CREAT | O_BINARY,
	       SH_DENYNO, MY_S_IREAD | MY_S_IWRITE);
  else
    fd =  open((my_string) FileName, access_flags | O_CREAT | O_BINARY,
	       MY_S_IREAD | MY_S_IWRITE);
#else
  fd = open(FileName, access_flags);
#endif

  DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_CREATE,
				   EE_CANTCREATEFILE, MyFlags));
} /* my_create */
Ejemplo n.º 22
0
VOID TMsgTag::Load ()
{
   int fd, i, Count;
   MSGTAGS *Buffer;

   Data.Clear ();

   if ((fd = sopen (DatFile, O_RDONLY|O_BINARY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
      if ((Buffer = (MSGTAGS *)malloc (sizeof (MSGTAGS) * MSGTAGS_INDEX)) != NULL) {
         do {
            Count = read (fd, Buffer, sizeof (MSGTAGS) * MSGTAGS_INDEX) / sizeof (MSGTAGS);
            for (i = 0; i < Count; i++) {
               if (Buffer[i].Free == FALSE && Buffer[i].UserId == UserId)
                  Data.Add (&Buffer[i], sizeof (MSGTAGS));
            }
         } while (Count == MSGTAGS_INDEX);
         free (Buffer);
      }
      close (fd);
   }

   if ((Buffer = (MSGTAGS *)Data.First ()) != NULL) {
      Tagged = Buffer->Tagged;
      strcpy (Area, Buffer->Area);
      LastRead = Buffer->LastRead;
      OlderMsg = Buffer->OlderMsg;
   }
}
Ejemplo n.º 23
0
static void lock_test_thread(void* arg)
{
	int	fd;

	fd=sopen(LOCK_FNAME,O_RDWR,SH_DENYNO);
	if(lock(fd,LOCK_OFFSET,LOCK_LEN)==0)
		printf("!FAILURE: Lock not effective between threads\n");
	else
		printf("Locks effective between threads\n");
	close(fd);
	fd=sopen(LOCK_FNAME,O_RDWR,SH_DENYNO);
	if(lock(fd,LOCK_OFFSET,LOCK_LEN))
		printf("Locks survive file open()/close() in other thread\n");
	else
		printf("!FAILURE: Locks do not survive file open()/close() in other thread\n");
	close(fd);
}
Ejemplo n.º 24
0
USHORT TUser::First ()
{
   USHORT RetVal = FALSE;

   if (fdDat == -1)
      fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
   if (fdIdx == -1)
      fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);

   if (fdDat != -1 && fdIdx != -1) {
      lseek (fdIdx, 0L, SEEK_SET);
      lseek (fdDat, 0L, SEEK_SET);
      RetVal = Next ();
   }

   return (RetVal);
}
Ejemplo n.º 25
0
Archivo: srv.c Proyecto: npe9/harvey
void
srv(Srv *srv)
{
	Req *r;

	fmtinstall('D', dirfmt);
	fmtinstall('F', fcallfmt);

	if(srv->fpool == nil)
		srv->fpool = allocfidpool(srv->destroyfid);
	if(srv->rpool == nil)
		srv->rpool = allocreqpool(srv->destroyreq);
	if(srv->msize == 0)
		srv->msize = 8192+IOHDRSZ;

	changemsize(srv, srv->msize);

	srv->fpool->srv = srv;
	srv->rpool->srv = srv;

	while(r = getreq(srv)){
		if(r->error){
			respond(r, r->error);
			continue;	
		}
		switch(r->ifcall.type){
		default:
			respond(r, "unknown message");
			break;
		case Tversion:	sversion(srv, r);	break;
		case Tauth:	sauth(srv, r);	break;
		case Tattach:	sattach(srv, r);	break;
		case Tflush:	sflush(srv, r);	break;
		case Twalk:	swalk(srv, r);	break;
		case Topen:	sopen(srv, r);	break;
		case Tcreate:	screate(srv, r);	break;
		case Tread:	sread(srv, r);	break;
		case Twrite:	swrite(srv, r);	break;
		case Tclunk:	sclunk(srv, r);	break;
		case Tremove:	sremove(srv, r);	break;
		case Tstat:	sstat(srv, r);	break;
		case Twstat:	swstat(srv, r);	break;
		}
	}

	free(srv->rbuf);
	srv->rbuf = nil;
	free(srv->wbuf);
	srv->wbuf = nil;
	srv->msize = 0;
	freefidpool(srv->fpool);
	srv->fpool = nil;
	freereqpool(srv->rpool);
	srv->rpool = nil;

	if(srv->end)
		srv->end(srv);
}
Ejemplo n.º 26
0
int _RTL_FUNC _open  (const char *__path, int __access,... /*unsigned mode*/)
{
   int amode ;
   va_list ap ;
   va_start(ap, __access) ;
   amode = *(int *)ap ;
   va_end(ap) ;
   return sopen(__path,__access & ~0x70,__access & 0x70,amode) ;
}
Ejemplo n.º 27
0
DICOMDataObject*
LoadImplicitLittleEndianFile(char* filename, unsigned int iVrSizeLimit)
{
	DICOMDataObject*	pDDO;
	int			handle;
	char			Buf[128 + 4];
	PDU_Service		PDU;
	unsigned int		iLastTime, iCurTime;
	CBufferedIO*		pBufferedIO;

	PDU.AttachRTC(&VRType);

#ifdef WIN32	
	handle = sopen( filename, O_RDONLY | O_BINARY, SH_DENYNO, S_IREAD);
#else
	handle = open( filename, O_RDONLY);
#endif

	if (handle == -1)
	{
		return NULL;
	}

	pBufferedIO = new CBufferedIO(iVrSizeLimit < 0x1000 ? 0x1000 : 0x8000);
	/* Find out whether marker 'DICM' exists */
	if (pBufferedIO->read(handle, Buf, 128 + 4) != 128 + 4)
	{
		delete pBufferedIO;
		close(handle);
		return NULL;
	}
	else
	{
		if (strncmp(Buf + 128, "DICM", 4) != 0)
		{
			pBufferedIO->lseek(handle, 0, SEEK_SET);
			/* We are at beginning of the VRs */
			pDDO = new DICOMDataObject;
			LoadImplicitLittleEndian(pDDO, pBufferedIO, handle, iVrSizeLimit);
//iLastTime = timeGetTime();
			delete pBufferedIO;
			close(handle);
//iCurTime = timeGetTime();
//printf("fopen=%d\r\n", iCurTime - iLastTime);
			return pDDO;
		}
		else
		{
			/* The function 'LoadImplicitLittleEndianFile' is not intended for
			   DICM files, however don't be fuzzy about it... */
			delete pBufferedIO;
			close(handle);
			pDDO = PDU.LoadDICOMDataObject(filename);
			return pDDO;
		}
	}
}
Ejemplo n.º 28
0
/*
 * DIPCliOpen
 */
dig_fhandle DIGCLIENT DIGCliOpen( const char *path, dig_open mode ) {

    dig_fhandle         ret;
    int                 flags;

    flags = O_BINARY;
    if( mode & DIG_READ )  flags |= O_RDONLY;
    if( mode & DIG_WRITE ) flags |= O_WRONLY;
    if( mode & DIG_TRUNC ) flags |= O_TRUNC;
    if( mode & DIG_CREATE ) {
        flags |= O_CREAT;
        ret = (dig_fhandle)sopen( path, flags, SH_DENYWR,
                                  S_IRWXU | S_IRWXG | S_IRWXO );
    } else {
        ret = (dig_fhandle)sopen( path, flags, SH_DENYWR );
    }
    return( ret );
}
Ejemplo n.º 29
0
void CTreemap::DrawTreemap(CDC *pdc, CRect rc, Item *root, const Options *options)
{
	RecurseCheckTree(root);

	if (options != NULL)
		SetOptions(options);

	if (rc.Width() <= 0 || rc.Height() <= 0)
		return;

	if (m_options.grid)
	{
		pdc->FillSolidRect(rc, m_options.gridColor);
	}
	else
	{
		// We shrink the rectangle here, too.
		// If we didn't do this, the layout of the treemap would
		// change, when grid is switched on and off.
		CPen pen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		CSelectObject sopen(pdc, &pen);
		pdc->MoveTo(rc.right - 1, rc.top);
		pdc->LineTo(rc.right - 1, rc.bottom);
		pdc->MoveTo(rc.left, rc.bottom - 1);
		pdc->LineTo(rc.right, rc.bottom - 1);
	}

	rc.right--;
	rc.bottom--;

	if (rc.Width() <= 0 || rc.Height() <= 0)
		return;

	if (root->TmiGetSize() > 0)
	{
		double surface[4];
		for (int i=0; i < 4; i++)
			surface[i]= 0;

		RecurseDrawGraph(pdc, root, rc, true, surface, m_options.height, 0);

#ifdef STRONGDEBUG	// slow, but finds bugs!
#ifdef _DEBUG
		for (int x=rc.left; x < rc.right - m_options.grid; x++)
		for (int y=rc.top; y < rc.bottom - m_options.grid; y++)
			ASSERT(FindItemByPoint(root, CPoint(x, y)) != NULL);
#endif
#endif

	}
	else
	{
		pdc->FillSolidRect(rc, RGB(0,0,0));
	}
}
Ejemplo n.º 30
0
USHORT TUser::Delete ()
{
   USHORT RetVal = FALSE, DoClose = FALSE;
   ULONG NameCrc;

   if (fdDat == -1) {
      fdDat = sopen (DatFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
      DoClose = TRUE;
   }
   if (fdIdx == -1) {
      fdIdx = sopen (IdxFile, O_RDWR|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE);
      DoClose = TRUE;
   }

   if (fdDat != -1 && fdIdx != -1) {
      NameCrc = StringCrc32 (Name, 0xFFFFFFFFL);
      lseek (fdIdx, 0L, SEEK_SET);
      while (RetVal == FALSE && read (fdIdx, &Idx, sizeof (Idx)) == sizeof (Idx)) {
         if (Idx.Deleted == FALSE && Idx.NameCrc == NameCrc)
            RetVal = TRUE;
      }

      if (RetVal == TRUE) {
         Idx.Deleted = TRUE;
         lseek (fdIdx, tell (fdIdx) - sizeof (Idx), SEEK_SET);
         write (fdIdx, &Idx, sizeof (Idx));
      }
   }

   if (DoClose == TRUE) {
      if (fdDat != -1) {
         close (fdDat);
         fdDat = -1;
      }
      if (fdIdx != -1) {
         close (fdIdx);
         fdIdx = -1;
      }
   }

   return (RetVal);
}