Beispiel #1
0
/*---------------------------------------------------------------------------
 * GetFileTitle
 * Purpose:  API to outside world to obtain the title of a file given the
 *              file name.  Useful if file name received via some method
 *              other that GetOpenFileName (e.g. command line, drag drop).
 * Assumes:  lpszFile  points to NULL terminated DOS filename (may have path)
 *           lpszTitle points to buffer to receive NULL terminated file title
 *           wBufSize  is the size of buffer pointed to by lpszTitle
 * Returns:  0 on success
 *           < 0, Parsing failure (invalid file name)
 *           > 0, buffer too small, size needed (including NULL terminator)
 *--------------------------------------------------------------------------*/
short FAR PASCAL
GetFileTitle(LPCSTR lpszFile, LPSTR lpszTitle, WORD wBufSize)
{
  short nNeeded;
  LPSTR lpszPtr;

  nNeeded = (WORD) ParseFile((ULPSTR)lpszFile);
  if (nNeeded >= 0)         /* Is the filename valid? */
    {
      if ((nNeeded = lstrlen(lpszPtr = lpszFile + nNeeded) + 1)
                                                        <= (short) wBufSize)
        {
          /* ParseFile() fails if wildcards in directory, but OK if in name */
          /* Since they aren't OK here, the check needed here               */
          if (mystrchr(lpszPtr, chMatchAny) || mystrchr(lpszPtr, chMatchOne))
            {
              nNeeded = PARSE_WILDCARDINFILE;  /* Failure */
            }
          else
            {
              lstrcpy(lpszTitle, lpszPtr);
              nNeeded = 0;  /* Success */
            }
        }
    }
  return(nNeeded);
}
Beispiel #2
0
// filter contains "NAME,Pattern for View CGI* , Pattern for Click CGI*"
char *AdvertCampMappingMatch( char *url, char filters[MAX_FILTERUNITS][MAX_FILTERSIZE], long *ret, long tot, char fcase )
{
	if ( url ){
		long i;
		char *p;
		char pattern[200];

		for ( i = 0; i<tot; i++) {
			p = filters[i];
			if ( *p != '!' ) {
				p = mystrchr( p, ',' );
				strcpyuntil( pattern , p+1, ',' );
				if ( match( url, pattern,fcase ) ){
					long cost = 0;
					*ret = 0;
					p = mystrchr( p+1, ',' );
					if (p){
						cost = myatoi( p+1 );
					}
					*ret = cost;
					return filters[i];
				}
			}
		}
	}
	return 0;
}
Beispiel #3
0
/* CompStatNum - compare two statistics string names, evaluating numerical addresses */
long CompStatNum(void *p1, void *p2, long *result)
{
	int		n1, n2;
	char	*str1 = ((Statistic *)p1)->GetName();
	char	*str2 = ((Statistic *)p2)->GetName();

	MACOS_PROGRESS_IDLE

	if (isdigit(*str1) && isdigit(*str2)) {

		for (;;) {
			n1 = myatoi(str1);
			n2 = myatoi(str2);
			if (n1 == n2) {
				str1 = mystrchr(str1,'.');
				if (!str1) { *result=0; return 0; }
				str2 = mystrchr(str2,'.');
				if (!str2) { *result=0; return 0; }
				++str1;
				++str2;
			} else if (n1 < n2) {
				*result=-1;
				return(0);
			} else {
				*result=1;
				return(0);
			}
		}

	} else {
		*result=strcmpd(str1,str2);
		return 0;   //was strcmpi
	}
}
Beispiel #4
0
// This will check the column types for X report and verify
// that the selected sort type exists in those columns
long IsThisSortValid( const long sorttype, const long reporttype )
{
	ReportTypesP	report_data;

	if ( sorttype == SORT_NAMES )
		return TRUE;

	if( report_data = FindReportTypeData( reporttype ) )
	{
		long columnID;
		char *formatStr, *type;
		columnID = report_data->typeID;

		formatStr = sFindHeadFormat( columnID );

		type = mystrchr( formatStr, ',' );

		if ( type )
		{
			long id, comp1, comp2, comp3 = 0;

			switch ( sorttype )
			{
				case SORT_BYTES:	comp1 =	'reqb'; break;
				case SORT_REQUESTS:	comp1 = 'reqb'; comp2 = 'requ'; break;
				case SORT_PAGES:	comp1 = 'page'; comp2 = 'cnt4'; comp3 = '%pag'; break;
				case SORT_ERRORS:	comp1 = 'erro'; break;
				case SORT_VISITS:	comp1 = 'Sess'; comp2 = 'sess'; break;
				case SORT_COUNTER:	comp1 = 'Visi'; comp2 = 'visi'; break;
			}



			type++;
			while( *type == ' ' )	type++;			// skip spaces

			while( type )
			{
				id = ReadLong( (unsigned char *)type );

				if ( id == comp1 || id == comp2 || id == comp3 )
					return TRUE;

				type = mystrchr( type, ',' );
				if ( type )
				{
					type++;
					while( *type == ' ' ) type++;			// skip spaces
				}
			}
		}
	}
	return FALSE;
}
Beispiel #5
0
// filter contains "NAME,Pattern for View CGI* , Pattern for Click CGI*"
char *AdvertMappingMatch( char *url, char filters[MAX_FILTERUNITS][MAX_FILTERSIZE], long *ret, long tot, char fcase )
{
	if ( url ){
		long i;
		char *p;
		char pattern[200];

		for ( i = 0; i<tot; i++) {
			p = filters[i];
			if ( *p != '!' ) {
				p = mystrchr( p, ',' );
				strcpyuntil( pattern , p+1, ',' );
				if ( match( url, pattern ,fcase ) ){
					*ret = 0;
					return filters[i];
				}
				p = strrchr( p, ',' );
				if ( match( url, p+1,fcase ) ){
					*ret = DRILLF_COUNTER4;
					return filters[i];
				}
			}
		}
	}
	return 0;
}
Beispiel #6
0
int main(void)
{
  char str[81];
  char ch;
  char *p;
  do
  {
    puts ("input range string:");
    gets (str);   //读取字符
    puts ("input match char:");
    ch = getchar ();
    getchar ();   //读取要搜索的字符
    p = mystrchr(str, ch);
    if (p)
    {
      puts ("Find!");
      puts (p);
    }
    else puts ("Can't find!");

    puts ("input an char except q to go on.");
    gets (str);
  }
  while (*str!= 'q');

  puts ("Quit.");
  return 0;
}
Beispiel #7
0
int mygetopt(int argc, char **argv, char *opts)
{
	static int sp = 0;
	static int optindex = 1;
	char *tmp = NULL;

	while(1)
	{
		if( optindex >= argc )
		{
			optindex = 1;
			sp = 0;
			return -1;
		}

		sp++;
		if( (argv[optindex][0] == '-') && (argv[optindex][sp] != 0) )
		{
			tmp = mystrchr(opts, argv[optindex][sp]);
			if( tmp )
				return argv[optindex][sp];
		}

		optindex++;
		sp = 0;
	}
}
Beispiel #8
0
/* GetIPAddress - get numerical address from string */
long GetIPAddress(char *hostname)
{
	int		i;
	long	addr = 0;
	
	for (i=3;;) {
		addr |= (long)myatoi(hostname) << 8*i;
		if (--i < 0) break;
		hostname = mystrchr(hostname,'.') + 1;
		if (!hostname) return(0L);
	}
	return(addr);
}
Beispiel #9
0
long strcmpManyFast( char *string, long *hash, char **comps )
{
	char *compare;
	long hashtofind;
	long *lp = hash, i;
	short srclen = -1;

	if ( *hash == 0 ) {			// hash up the strings for fast lookups
		char **cs = comps;
		i = 0;
		while( *cs && i<256){
			*lp++ = HashIt( *cs++, 0xfff );
			i++;
		}
	}

	lp = hash;
	if ( MyPrefStruct.useCGI ){
		compare = mystrchr( string, '?' );
		if ( compare )
			srclen = compare - string;
	}

	hashtofind = HashIt( string, srclen );

	while( *hash ){
		if ( *hash == hashtofind )
			return 0;
		hash++;
	}
	return 1;

	//slow way to do it here....
	while( (compare=*comps) ){
		if ( strcmpiPart( compare, string ) == 0 )
			return 0;
		comps++;
	}
	return 1;
}
Beispiel #10
0
/* Render the cstring provided to an escaped version that can be printed. */
static char *print_string_ptr(const char *str)
{
	const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
	
	if (!str) return cJSON_strdup("");

	ptr=str;
	while ((token=*ptr) && ++len) 
	{
		if (mystrchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;
	}
	
	out=(char*)cJSON_malloc(len+3);
	if (!out) return 0;

	ptr2=out;ptr=str;
	*ptr2++='\"';
	while (*ptr)
	{
		if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
		else
		{
			*ptr2++='\\';
			switch (token=*ptr++)
			{
				case '\\':	*ptr2++='\\';	break;
				case '\"':	*ptr2++='\"';	break;
				case '\b':	*ptr2++='b';	break;
				case '\f':	*ptr2++='f';	break;
				case '\n':	*ptr2++='n';	break;
				case '\r':	*ptr2++='r';	break;
				case '\t':	*ptr2++='t';	break;
				default: _hx_sprintf(ptr2,"u%04x",token);ptr2+=5;	break;	/* escape and print */
			}
		}
	}
	*ptr2++='\"';*ptr2++=0;
	return out;
}
Beispiel #11
0
// return the name of the OS string
char *InterpretOperSysString( char *opersys_str, long *outOStype, long *outOSid  )
{
	char *osPtr, *s = opersys_str;
	long OStype = 4, OSid, i;		// 0=bad!!!

	if ( !outOStype || !outOSid ) return 0;

	i = 0;
	s = mystrchr( opersys_str, '(' );
	// Sometimes some linux agents dont have brackets and basic streaming agents dont either
	if ( !s )
		s = opersys_str;

	OSid = OS_UNKNOWN;

	if ( s )
	{
		int fcase = FALSE;
		opersys_str = s;

		if ( (osPtr = mystrstr(  opersys_str, "Win" )) ){
			opersys_str = osPtr;
			OStype = 1;

			if ( (osPtr = mystrstr(  opersys_str, "16" )) ){
				OSid = OS_WIN31;
			} else
			if ( (osPtr = mystrstr(  opersys_str, "95" )) ){
				OSid = OS_WIN95;
			} else
			if ( (match(  opersys_str, "*9x?4.90*", fcase )) ){
				OSid = OS_WINME;
			} else
			if ( (osPtr = mystrstr(  opersys_str, "98" )) ){
				OSid = OS_WIN98;
			} else
			if ( (match( opersys_str, "Windows?NT?5.0*", fcase )) ){
				OSid = OS_WIN2000;
			} else
			if ( (match( opersys_str, "Windows?NT?5.1*", fcase )) ){
				OSid = OS_WINXP;
			} else
			if ( (match( opersys_str, "Windows?NT?5*", fcase )) ){
				OSid = OS_WIN2000;
			} else
			if ( (match( opersys_str, "Windows?2002*", fcase )) ){
				OSid = OS_WINXP;
			} else
			if ( (match( opersys_str, "Windows?2000*", fcase )) ){
				OSid = OS_WIN2000;
			} else
			if ( (match( opersys_str, "Windows?NT*", fcase )) ){
				OSid = OS_WINNT;
			} else
			if ( (osPtr = mystrstr(  opersys_str, "Windows%20NT" )) ){
				OSid = OS_WINNT;
			} else
			if ( (match(  opersys_str, "WinNT?5.0", fcase  )) ){
				OSid = OS_WIN2000;
			} else
			if ( (match(  opersys_str, "WinNT?5.1", fcase  )) ){
				OSid = OS_WINXP;
			} else
			if ( (osPtr = mystrstr(  opersys_str, "WinNT" )) ){
				OSid = OS_WINNT;
			} else
			if ( (osPtr = mystrstr(  opersys_str, "Win" )) ){
				OSid = OS_WIN31;
			}
		} else
		if ( (osPtr = mystrstr(  opersys_str, "NT 5" )) ){
			OSid = OS_WINNT;
			OStype = 1;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "PowerPC" )) ){
			OStype = 2;
			if ( (osPtr = mystrstr(  opersys_str, "OmniWeb" )) ){
				OSid = OS_MACOSX;
			} else
			if ( (osPtr = mystrstr(  opersys_str, "MSIE 5.1" )) ){
				OSid = OS_MACOSX;
			} else
			{
				OSid = OS_MACOS;
			}
		} else
		if ( (osPtr = mystrstr(  opersys_str, "PPC" )) ){
			OSid = OS_MACOS;
			OStype = 2;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "68k" )) ){
			OSid = OS_MACOS;
			OStype = 2;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "Mac" )) ){
			OSid = OS_MACOS;
			OStype = 2;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "WebTV" )) ){
			OSid = 8;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "SunOS" )) ){
			OSid = 9;
			OStype = 3;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "IRIX" )) ){
			OSid = 10;
			OStype = 3;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "AIX" )) ){
			OSid = 11;
			OStype = 3;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "HP-UX" )) ){
			OSid = 12;
			OStype = 3;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "OSF" )) ){
			OSid = 13;
			OStype = 3;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "FreeBSD" )) ){
			OSid = 14;
			OStype = 3;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "Linux" )) ){
			OSid = 15;
			OStype = 3;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "Amiga" )) ){
			OSid = 16;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "OpenVMS" )) ){
			OSid = 17;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "OS/2" )) ){
			OSid = 18;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "BeOS" )) ){
			OSid = 20;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "gozilla" )) ){
			OSid = OS_WINUNKNOWN; OStype = 1;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "downloadaccelerator.com" )) ){
			OSid = OS_WINUNKNOWN; OStype = 1;
		} else
		if ( (osPtr = mystrstr(  opersys_str, "Lynx" )) ){
			OSid = 19;
			OStype = 3;
		}
	}
	
	*outOStype = OStype;
	*outOSid = OSid;

	return opersysStrings[OSid];
}
Beispiel #12
0
int main(){

  printf("\n\n");

  char test[]="testing_the_length_of_this_string";

  printf("Test for strlen:\n string: %s\n length: %d\n",test,mystrlen(test));

  printf("\n");

  char src[]="source",
    dest[]="destination";

  printf("Test for strcpy:\n before copying:\n  src: %s\n  dest: %s\n",src,dest);

  printf(" after copying:\n  src: %s\n  dest: %s\n",src,mystrcpy(dest,src));

  printf("\n");

  char src0[]="source",
    dest0[]="destination";
  int n=3;

  printf("Test for strncpy:\n before copying:\n  src: %s\n  dest: %s\n  n: %d\n",src0,dest0,n);

  printf(" after copying:\n  src: %s\n  dest: %s\n",src,mystrncpy(dest0,src0,n));

  printf("\n");

  char src1[]="source",
    dest1[]="destination";

  printf("Test for strcat:\n before concatenation:\n  src: %s\n  dest: %s\n",src1,dest1);

  printf(" after concatenation:\n  src: %s\n  dest: %s\n",src1,mystrcat(dest1,src1));

  printf("\n");

  char src2[]="source",
    dest2[]="destination";
  int m=3;

  printf("Test for strncat:\n before concatenation:\n  src: %s\n  dest: %s\n  n: %d\n",src2,dest2,m);

  printf(" after concatenation:\n  src: %s\n  dest: %s\n",src2,mystrncat(dest2,src2,m));

  printf("\n");

  char stra[]="apple",
    strb[]="pie";

  printf("Test for strcmp:\n a: %s\n b: %s\n a compared to b: %d\n",stra,strb,mystrcmp(stra,strb));

  printf("\n");

  char strc[]="pie",
    strd[]="bpple";

  printf("Test 2 for strcmp:\n a: %s\n b: %s\n a compared to b: %d\n",strc,strd,mystrcmp(strc,strd));

  printf("\n");

  char stre[]="x",
    strf[]="x";

  printf("Test for 3 strcmp:\n a: %s\n b: %s\n a compared to b: %d\n",stre,strf,mystrcmp(stre,strf));

  printf("\n");

  char s[]="string",
    c1='r',
    c2='a';

  printf("Test for strchr:\n s: %s\n c1: %c\n c2: %c\n char c1 as found in in s: [%c] at location %p\n char c2 as found in s: [%c] at location %p\n",s,c1,c2,*mystrchr(s,c1),mystrchr(s,c1),*mystrchr(s,c2),mystrchr(s,c2));

  printf("\n");

  char haystack[]="haystack",
    needle1[]="needle",
    needle2[]="sta";

  printf("Test for strstr:\n haystack: %s\n needle1: %s\n needle2: %s\n substring beginning with needle1 in haystack: [%s] at location %p (the terminating null)\n substring beginning with needle2 in haystack: [%s] at location %p\n",haystack,needle1,needle2,mystrstr(haystack,needle1),mystrstr(haystack,needle1),mystrstr(haystack,needle2),mystrstr(haystack,needle2));

  printf("\n");

  char haystack2[]="ababa",
    needle1a[]="b",
    needle2a[]="ab";

  printf("Test 2 for strstr:\n haystack: %s\n needle1: %s\n needle2: %s\n substring beginning with needle1 in haystack: [%s]\n substring beginning with needle2 in haystack: [%s]\n",haystack2,needle1a,needle2a,mystrstr(haystack2,needle1a),mystrstr(haystack2,needle2a));
  printf("(demonstrates that the function looks for the first occurence of the substring (needle), not the last or an arbitrary one)\n");

  printf("\n");

  return 0;
}
Beispiel #13
0
/** The main thing.
 * @param argc the number of tokens on the input line.
 * @param argv an array of tokens.
 * @return 0 on success, 1-255 on failure
 */
int
main(int argc, char *argv[])
{
  // a sample string
  char *string = "The quick brown fox jumped over the lazy dog's back.";
  char *missing = "ABCDEFGHIJKLMNOPQRS-UVWXYZ!@#$%^&*()_+1234567890=";
  // a few select primes
  int intArray[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; 

  int index;
  int i;
  int arrayCount = sizeof(intArray) / sizeof(intArray[0]);

  // enable malloc checks.
  setenv("MALLOC_CHECK", "1", 1);

  // check that the stride is prime to the array size; since it's prime and
  // smaller than the array size, just a divisibility check should do it.
  // If this fails, the loop below wouldn't work as intended.
  assert(arrayCount % INDEX_STRIDE != 0);

  ////////////////////////////////////////////////////////////////////// test mystrchr
  fprintf(stderr, "///////////////////////////// testing mystrchr\n");
  fprintf(stderr, "Looking for: ");
  for (i = 0; string[i]; i++) {
    fprintf(stderr, "%c", string[i]);
    assert(strchr(string, string[i]) == mystrchr(string, string[i]));
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "Looking for: ");
  for (i = 0; missing[i]; i++) {
    fprintf(stderr, "%c", missing[i]);
    assert(strchr(string, missing[i]) == mystrchr(string, missing[i]));
  }
  fprintf(stderr, "\n");
  fprintf(stderr, " !!! mystrchr is okay\n");

  ////////////////////////////////////////////////////////////////////// test intindex
  fprintf(stderr, "///////////////////////////// testing intindex\n");
  fprintf(stderr, "Looking for:");
  index = 5;
  for (i = 0; i < arrayCount; i++) {
    fprintf(stderr, " %d", intArray[index]);
    assert(index == intindex(intArray[index], intArray, arrayCount));
    index = (index + 7) % arrayCount;
  }

  fprintf(stderr, "\n");
  fprintf(stderr, "Looking for:");
  // Make sure it finds no even numbers after 2.
  for (i = 0; i < arrayCount; i++) {
    fprintf(stderr, " %d", 2 * i + 4);
    assert(intindex(2 * i + 4, intArray, arrayCount) == -1);
  }

  fprintf(stderr, "\n");
  fprintf(stderr, " !!! intindex is okay\n");
  printf("Success!\n");

  return EXIT_SUCCESS;
}
short PROC_Raptor(char *buffer,HitDataPtr Line)
{
	char 	*ptr;		
	short	i=1, tot;
	static char globalyear[8];

	MemClr( format, 25*sizeof(void*) );
	MemClr( Line, sizeof( struct HitData ) );
	//Tokenise line into format fields 1 to 25 from \t
	format[i++]=buffer;
	while (*buffer && i<FORMATSIZE ) {
		if ( *buffer == ' ') {
			format[i++] = buffer+1;
			*buffer=0;
		}
		buffer++;
	}
	tot = i;
	//check if it is a valid format first
	if (tot<8)
		return 0;

	if ( Line->lineNum > 1 )
	{
		sprintf( GlobalDate, "%02d/%s/%s", Month2Num( format[1] ), format[2], globalyear );
		Line->date = GlobalDate;				//Jan 08 02:53:23
	}
	Line->time = format[3];
	Line->stat = format[6];
	if( Line->protocol = format[5] ){
		ptr = mystrchr( Line->protocol, '[' );	// remove [ from the protocol field
		if ( ptr ) *ptr = 0;
	}

	i = 5;
	while( i<=tot ){
		if ( format[5] && format[i] ){
			if ( ptr=strstr( format[i], "src=" ) ){
				if( Line->clientaddr = 4+ptr ){
					if ( ptr=mystrchr( 4+ptr, '/' ) ) *ptr = ':';			// replace / with : for port number of address
				}
			} else
			if ( ptr=strstr( format[i], "srcname=" ) )
				Line->user = 8+ptr;
			else
			if ( ptr=strstr( format[i], "Year" ) )
			{
				// This is a line (generally the 1st line) which gives you the current year for all the other lines which 
				// just give the day & month (as well as the time)
				mystrcpy( globalyear, format[i+2] );
				globalyear[4] = 0;
				sprintf( GlobalDate, "%02d/%s/%s", Month2Num( format[1] ), format[2], globalyear );
				Line->date = GlobalDate;				//Jan 08 02:53:23
				return 0; // This is a line with the year in it
			}
			else
			if ( ptr=strstr( format[i], "dst=" ) ){
				if( Line->sourceaddr = 4+ptr ){
					if ( ptr=mystrchr( 4+ptr, '/' ) ) {
						Line->port = myatoi( ptr+1 );
						*ptr = 0;			// replace / with : for port number of address
					}
				}
			} else
			if ( ptr=strstr( format[i], "dstname=" ) ){
				if( Line->file = 8+ptr ){
					if ( ptr=mystrchr( 8+ptr, '/' ) ){
						Line->port = myatoi( ptr+1 );
						*ptr = 0;			// replace / with : for port number of address
					}
				}
			} else
			if ( ptr=strstr( format[i], "arg=" ) ){			// if name enclosed in <> only use content
				if ( ptr[4] == '<' ) {
					ptr++;
					if( Line->file ) mystrcat( Line->file, " , " );
				} else
					if( Line->file ) mystrcat( Line->file, "/" );

				if ( Line->file ) {
					mystrcat( Line->file, 4+ptr );
				} else
					Line->file = 4+ptr;
				if ( ptr=strrchr( ptr, '>' ) ) *ptr = 0;
			} else
			if ( ptr=strstr( format[i], "proto=" ) )
				Line->protocol = 6+ptr;
			else
			if ( ptr=strstr( format[i], "Protocol=" ) )
				Line->protocol = 9+ptr;
			else
			if ( ptr=strstr( format[i], "sent=" ) )
				Line->bytesIn = myatoi( 5+ptr );
			else
			if ( ptr=strstr( format[i], "rcvd=" ) )
				Line->bytes = myatoi( 5+ptr );
			else
			if ( ptr=strstr( format[i], "result=" ) )
				Line->stat = 7+ptr;
			else
			if ( ptr=strstr( format[i], "duration=" ) )
				Line->ms = myatoi( 9+ptr ) * 1000;
			else
			if ( ptr=strstr( format[i], "user=" ) ){
				if ( ptr[5] == '<' ) ptr++;
				Line->clientaddr = 4+ptr;
				if ( ptr=strrchr( ptr, '>' ) ) *ptr = 0;
			}
		}
		i++;
	}
	return 1;
}
/*
Nov 30 00:00:03 eaglent firelogd[127]: 108 starting new log file. UTC offset is +1000, Year is 1998, Eagle is 5.0.1i, OS is "NT 4.0 (Build 1381: Service Pack 3)", Platform is "Intel x86"
Nov 30 00:00:11 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for MailServer for . - no progress possible (139.130.4.4/No response)
Nov 30 00:00:19 eaglent xntpd[132]: 120 NTP Info: offset 0.023925 sec freq 13.340 ppm poll 10
Nov 30 00:27:35 eaglent smtp[357]: 121 Statistics: duration=9.19 user=<*****@*****.**> sent=1404 rcvd=314 srcif=Vpn8 src=203.32.30.36/29807 srcname=malvern.starway.net.au dstif=Vpn5 dst=172.168.1.220/25 dstname=main.unisuper.com.au op="To 1 recips" arg=<*****@*****.**> result="250 Data received OK." proto=smtp rule=3 
Nov 30 00:41:30 eaglent httpd[338]: 121 Statistics: duration=0.03 sent=262 rcvd=503 srcif=Vpn6 src=212.17.88.76/1377 srcname=TK212017088076.tuwien.teleweb.at dstif=Vpn5 dst=172.168.1.230/80 dstname=www.unisuper.com.au op=GET arg=/python/ result="404 Not Found" proto=http rule=18 
Nov 30 00:46:50 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for MailServer for nothnet.com.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:46:50 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for MailServer for netscape.net.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:46:50 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for MailServer for netscape.net.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:46:50 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for MailServer for netscape.net.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:46:50 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for MailServer for mugs.cc.monash.edu.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:46:50 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for MailServer for . - no progress possible (139.130.4.4/No response)
Nov 30 00:47:04 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for Address for nothnet.com.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:47:06 eaglent httpd[338]: 121 Statistics: duration=0.04 sent=259 rcvd=375 srcif=Vpn6 src=195.92.199.104/21876 srcname=webcache05s.cache.pol.co.uk dstif=Vpn5 dst=172.168.1.230/80 dstname=www.unisuper.com.au op=GET arg=/startrek/strek.htm result="404 Not Found" proto=http rule=18 
Nov 30 00:47:18 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for Address for nothnet.com.au.com.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:47:34 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for Address for netscape.net.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:47:48 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for Address for netscape.net.au.com.au. - no progress possible (139.130.4.4/No response)
Nov 30 00:48:04 eaglent dnsd[129]: 120 dnsd Info: Failed to handle request from 172.168.1.245 for Address for netscape.net.au. - no progress possible (139.130.4.4/No response)
*/
short PROC_Firewall(char *buffer,HitDataPtr Line)
{
	char 	*ptr;		
	short	i=1, tot;
	static char globalyear[8];
	static char newFieldFound = 0;
	static char newFieldMsgDisplayed = 0;
	static char newFieldName[32];

	MemClr( format, 25*sizeof(void*) );
	MemClr( Line, sizeof( struct HitData ) );
	//Tokenise line into format fields 1 to 25 from \t
	format[i++]=buffer;
	while (*buffer && i<FORMATSIZE ) {
		if ( *buffer == ' ') {
			format[i++] = buffer+1;
			*buffer=0;
		}
		buffer++;
	}
	tot = i;
	//check if it is a valid format first
	if (tot<8)
		return 0;

	i = 1;
	while( i<tot )
	{
		switch( *format[i] )
		{
		case 's':
			if ( ptr=strstr( format[i], "src=" ) ){
				if( Line->clientaddr = 4+ptr ){
					if ( ptr=mystrchr( 4+ptr, '/' ) ) *ptr = ':';			// replace / with : for port number of address
				}
			} else
			if ( ptr=strstr( format[i], "srcname=" ) )
				Line->user = 8+ptr;
			else
			if ( ptr=strstr( format[i], "service=" ) )
				Line->protocol = 8+ptr;
			else
				newFieldFound = 1;
			break;
		case 'd':
			if ( ptr=strstr( format[i], "dst=" ) ){
				if( Line->sourceaddr = 4+ptr ){
					if ( ptr=mystrchr( 4+ptr, '/' ) ) {
						Line->port = myatoi( ptr+1 );
						*ptr = 0;			// replace / with : for port number of address
					}
				}
			} else
			if ( ptr=strstr( format[i], "dstname=" ) ){
				if( Line->file = 8+ptr ){
					if ( ptr=mystrchr( 8+ptr, '/' ) ){
						Line->port = myatoi( ptr+1 );
						*ptr = 0;			// replace / with : for port number of address
					}
				}
			} else
			if ( ptr=strstr( format[i], "duration=" ) )
				Line->ms = myatoi( 9+ptr );
			else
				newFieldFound = 1;
			break;
		case 'p':
			if ( ptr=strstr( format[i], "port=" ) )
				Line->port = myatoi( 5+ptr );
			else
//			if ( ptr=strstr( format[i], "policy=" ) )
//				Line->policy = myatoi( 7+ptr );
//			else
				newFieldFound = 1;
			break;
		case 'a':
//			if ( ptr=strstr( format[i], "action=" ) )
//				Line->action = 7+ptr;
//			else
				newFieldFound = 1;
			break;
		case 't':
			//Fix this
			if ( ptr=strstr( format[i], "time=\"" ) )
			{
				// This is a line (generally the 1st line) which gives you the current year for all the other lines which 
				// just give the day & month (as well as the time)
				//mystrncpyNull( globalyear, format[i]+4, 5 );
				//globalyear[4] = 0;
				Line->date = ConvLDate( format[i]+6, Line->newdate );
//				sscanf( 
//				sprintf( GlobalDate, "%d-%d-%d", format[i] );
				//Line->date = GlobalDate;
				i++;
				char *p = format[i];
				while( *p != '\"' )
					p++;
				p = 0;
				Line->time = format[i];

				//return 0; // This is a line with the year in it
			}
			else
				newFieldFound = 1;
			break;
		}
		if ( newFieldFound )
		{
			if ( !newFieldMsgDisplayed )
			{
				// Display a message to the user...
				//ErrorMsg( format[i] );
				newFieldMsgDisplayed = 1;
			}
			newFieldFound = 0;
		}
		else
		{
			if ( ptr=strstr( format[i], "arg=" ) ){			// if name enclosed in <> only use content
				if ( ptr[4] == '<' ) {
					ptr++;
					if( Line->file ) strcat( Line->file, " , " );
				} else
					if( Line->file ) strcat( Line->file, "/" );

				if ( Line->file ) {
					strcat( Line->file, 4+ptr );
				} else
					Line->file = 4+ptr;
				if ( ptr=strrchr( ptr, '>' ) ) *ptr = 0;
			} else
			if ( ptr=strstr( format[i], "proto=" ) )
				Line->protocol = 6+ptr;
			else
			if ( ptr=strstr( format[i], "Protocol=" ) )
				Line->protocol = 9+ptr;
			else
			if ( ptr=strstr( format[i], "sent=" ) )
				Line->bytesIn = myatoi( 5+ptr );
			else
			if ( ptr=strstr( format[i], "rcvd=" ) )
				Line->bytes = myatoi( 5+ptr );
			else
			if ( ptr=strstr( format[i], "result=" ) )
				Line->stat = 7+ptr;
			else
			if ( ptr=strstr( format[i], "duration=" ) )
				Line->ms = myatoi( 9+ptr ) * 1000;
			else
			if ( ptr=strstr( format[i], "user=" ) ){
				if ( ptr[5] == '<' ) ptr++;
				Line->clientaddr = 4+ptr;
				if ( ptr=strrchr( ptr, '>' ) ) *ptr = 0;
			}
		}
		i++;
	}
	return 1;
}
Beispiel #16
0
LPSTR
FindP1284Key(
    PINIPORT    pIniPort,
    LPSTR   lpKey
    )
/*++

Routine Description:
    Find the 1284 key identifying the device id

Arguments:
    status  : status

Return Value:
    Pointer to the command string, NULL if not found.

--*/
{
    LPSTR   lpValue;                // Pointer to the Key's value
    WORD    wKeyLength;             // Length for the Key (for stringcmps)
    LPSTR   ret = NULL;

    // While there are still keys to look at.
#ifdef DEBUG
    OutputDebugStringA("PJLMon!DeviceId : <");
    OutputDebugStringA(lpKey);
    OutputDebugStringA(">\n");
#endif

    while (lpKey && *lpKey) {

        //
        // Is there a terminating COLON character for the current key?
        //
        if (!(lpValue = mystrchr(lpKey, COLON)) ) {

            //
            // N: OOPS, somthing wrong with the Device ID
            //
            return ret;
        }

        //
        // The actual start of the Key value is one past the COLON
        //
        ++lpValue;

        //
        // Compute the Key length for Comparison, including the COLON
        // which will serve as a terminator
        //
        wKeyLength = (WORD)(lpValue - lpKey);

        //
        // Compare the Key to the Know quantities.  To speed up the comparison
        // a Check is made on the first character first, to reduce the number
        // of strings to compare against.
        // If a match is found, the appropriate lpp parameter is set to the
        // key's value, and the terminating SEMICOLON is converted to a NULL
        // In all cases lpKey is advanced to the next key if there is one.
        //
        if ( *lpKey == 'C' ) {

            //
            // Look for COMMAND SET or CMD
            //
            if ( !mystrncmp(lpKey, COMMAND, wKeyLength) ||
                 !mystrncmp(lpKey, CMD, wKeyLength) ) {

                ret = lpValue;
            }
        }

        // Go to the next Key

        if ( lpKey = mystrchr(lpValue, SEMICOLON) ) {

            *lpKey = '\0';
            ++lpKey;
        }
    }

    return ret;
}
Beispiel #17
0
long GetPartialFileData( char *filename, long fpos, char *data, long linesWanted, short win )
{
	long fp;
	long len = 0, charCount = 0, linesGot;

	if ( linesWanted == 0 )
		linesWanted = LINESTOREAD;

	linesGot = 0;

	if ( fp = (long)gzopen( filename, "r" ) ){
		char *mem = (char*)malloc( (2+linesWanted)*LINELEN );
		char c, *p;

		memset( mem, 0, (2+linesWanted)*LINELEN );
		gzseek( (gzFile)fp, fpos, SEEK_SET );
		//OutDebugs( "In GetPartialFileData() at file pos (fpos) %d trying to read %d bytes from %s", fpos, linesWanted*LINELEN, filename );

		if( (len = gzread( (gzFile)fp, mem, linesWanted*LINELEN )) )
		{
			//OutDebugs( "Read %d bytes", len );
			mem[len] = 0;
			if ( fpos != 0 ) // If this is the first line, then we don't search for the first "return" ie, new line as we are at the begining
			{
				p = mystrchr( mem, '\r' );
				if ( !p )
					p = mystrchr( mem, '\n' );
				if ( !p )
					p = mem;
			}
			else
				p = mem;

			while( linesGot < linesWanted && (c = *p++) )
			{
				*data++ = c;
				if( c=='\r' || c=='\n' )
				{
					linesGot++;
					charCount++;
					if( *p=='\n' )
					{
						charCount++;
						*data++ = *p++;
					}
				}
				else if ( linesGot > 0 )
					charCount++;
			}
			*data++ = 0;
		}
		free( mem );
		gzclose( (gzFile)fp );
	}

	// Update the window's stats
	winStats[win].totalLines += linesGot;
	winStats[win].totalLinesLen += charCount;

	return charCount;
}
Beispiel #18
0
/*
 * NAME:	hfs->format()
 * DESCRIPTION:	write a new filesystem
 */
int hfs_format(char *path, int pnum, char *vname)
{
  hfsvol vol;
  btree *ext = &vol.ext;
  btree *cat = &vol.cat;
  unsigned int vbmsz;
  int i, result = 0;
  block vbm[16];
  char *map;

  if (mystrchr(vname, ':'))
    {
      ERROR(EINVAL, "volume name may not contain colons");
      return -1;
    }

  i = strlen(vname);
  if (i < 1 || i > HFS_MAX_VLEN)
    {
      ERROR(EINVAL, "volume name must be 1-27 chars");
      return -1;
    }

  vol.flags  = 0;
  vol.pnum   = pnum;
  vol.vstart = 0;
  vol.vlen   = 0;
  vol.lpa    = 0;
  vol.vbm    = vbm;
  vol.cwd    = HFS_CNID_ROOTDIR;

  vol.refs   = 0;
  vol.files  = 0;
  vol.dirs   = 0;
  vol.prev   = 0;
  vol.next   = 0;

#if 0
  vol.fd = open(path, O_RDWR);

  if (vol.fd < 0)
    {
      ERROR(errno, "error opening device for writing");
      return -1;
    }
#endif

  if (l_lockvol(&vol) < 0)
    {
#if 0
      close(vol.fd);
#endif
      return -1;
    }

  if (pnum > 0)
    {
      if (l_readpm(&vol) < 0)
	{
#if 0
	  close(vol.fd);
#endif
	  return -1;
	}
    }
  else  /* determine size of entire device */
    {
      unsigned long low, high, mid;
      block b;

      for (low = 0, high = 2879; b_readlb(&vol, high, &b) >= 0; high *= 2)
	low = high;

      while (low < high - 1)
	{
	  mid = (low + high) / 2;

	  if (b_readlb(&vol, mid, &b) < 0)
	    high = mid;
	  else
	    low = mid;
	}

      vol.vlen = low + 1;
    }

  if (vol.vlen < 800 * 1024 / HFS_BLOCKSZ)
    {
#if 0
      close(vol.fd);
#endif

      ERROR(EINVAL, "volume size must be >= 800K");
      return -1;
    }

  /* initialize volume geometry */

  vol.lpa = 1 + vol.vlen / 65536;

  vbmsz = (vol.vlen / vol.lpa + 4095) / 4096;

  vol.mdb.drSigWord  = 0x4244;
  vol.mdb.drCrDate   = d_tomtime(/*time*/(0));
  vol.mdb.drLsMod    = vol.mdb.drCrDate;
  vol.mdb.drAtrb     = 0;
  vol.mdb.drNmFls    = 0;
  vol.mdb.drVBMSt    = 3;
  vol.mdb.drAllocPtr = 0;
  vol.mdb.drNmAlBlks = (vol.vlen - 5 - vbmsz) / vol.lpa;
  vol.mdb.drAlBlkSiz = vol.lpa * HFS_BLOCKSZ;
  vol.mdb.drClpSiz   = vol.mdb.drAlBlkSiz * 4;
  vol.mdb.drAlBlSt   = 3 + vbmsz;
  vol.mdb.drNxtCNID  = HFS_CNID_ROOTDIR;  /* modified later */
  vol.mdb.drFreeBks  = vol.mdb.drNmAlBlks;

  strcpy(vol.mdb.drVN, vname);

  vol.mdb.drVolBkUp  = 0;
  vol.mdb.drVSeqNum  = 0;
  vol.mdb.drWrCnt    = 0;
  vol.mdb.drXTClpSiz = vol.mdb.drNmAlBlks / 128 * vol.mdb.drAlBlkSiz;
  vol.mdb.drCTClpSiz = vol.mdb.drXTClpSiz;
  vol.mdb.drNmRtDirs = 0;
  vol.mdb.drFilCnt   = 0;
  vol.mdb.drDirCnt   = -1;  /* incremented when root folder is created */

  for (i = 0; i < 8; ++i)
    vol.mdb.drFndrInfo[i] = 0;

  vol.mdb.drVCSize   = 0;
  vol.mdb.drVBMCSize = 0;
  vol.mdb.drCtlCSize = 0;

  vol.mdb.drXTFlSize = 0;
  vol.mdb.drCTFlSize = 0;

  for (i = 0; i < 3; ++i)
    {
      vol.mdb.drXTExtRec[i].xdrStABN    = 0;
      vol.mdb.drXTExtRec[i].xdrNumABlks = 0;

      vol.mdb.drCTExtRec[i].xdrStABN    = 0;
      vol.mdb.drCTExtRec[i].xdrNumABlks = 0;
    }

  /* initialize volume bitmap */

  memset(vol.vbm, 0, sizeof(vbm));

  /* create extents overflow file */

  ext->f.vol   = &vol;
  ext->f.parid = 0;
  strcpy(ext->f.name, "extents overflow");

  ext->f.cat.cdrType          = cdrFilRec;
  /* ext->f.cat.cdrResrv2 */
  ext->f.cat.u.fil.filFlags   = 0;
  ext->f.cat.u.fil.filTyp     = 0;
  /* ext->f.cat.u.fil.filUsrWds */
  ext->f.cat.u.fil.filFlNum   = HFS_CNID_EXT;
  ext->f.cat.u.fil.filStBlk   = 0;
  ext->f.cat.u.fil.filLgLen   = 0;
  ext->f.cat.u.fil.filPyLen   = 0;
  ext->f.cat.u.fil.filRStBlk  = 0;
  ext->f.cat.u.fil.filRLgLen  = 0;
  ext->f.cat.u.fil.filRPyLen  = 0;
  ext->f.cat.u.fil.filCrDat   = vol.mdb.drCrDate;
  ext->f.cat.u.fil.filMdDat   = vol.mdb.drLsMod;
  ext->f.cat.u.fil.filBkDat   = 0;
  /* ext->f.cat.u.fil.filFndrInfo */
  ext->f.cat.u.fil.filClpSize = 0;

  for (i = 0; i < 3; ++i)
    {
      ext->f.cat.u.fil.filExtRec[i].xdrStABN     = 0;
      ext->f.cat.u.fil.filExtRec[i].xdrNumABlks  = 0;

      ext->f.cat.u.fil.filRExtRec[i].xdrStABN    = 0;
      ext->f.cat.u.fil.filRExtRec[i].xdrNumABlks = 0;
    }
  /* ext->f.cat.u.fil.filResrv */
  f_selectfork(&ext->f, 0);

  ext->f.clump = vol.mdb.drXTClpSiz;
  ext->f.flags = 0;

  ext->f.prev = ext->f.next = 0;

  n_init(&ext->hdrnd, ext, ndHdrNode, 0);

  ext->hdrnd.nnum       = 0;
  ext->hdrnd.nd.ndNRecs = 3;
  ext->hdrnd.roff[1]    = 0x078;
  ext->hdrnd.roff[2]    = 0x0f8;
  ext->hdrnd.roff[3]    = 0x1f8;

  memset(HFS_NODEREC(ext->hdrnd, 1), 0, 128);

  ext->hdr.bthDepth    = 0;
  ext->hdr.bthRoot     = 0;
  ext->hdr.bthNRecs    = 0;
  ext->hdr.bthFNode    = 0;
  ext->hdr.bthLNode    = 0;
  ext->hdr.bthNodeSize = HFS_BLOCKSZ;
  ext->hdr.bthKeyLen   = 0x07;
  ext->hdr.bthNNodes   = 0;
  ext->hdr.bthFree     = 0;
  for (i = 0; i < 76; ++i)
    ext->hdr.bthResv[i] = 0;

  map = ALLOC(char, HFS_MAP1SZ);
  if (map == 0)
    {
      if (result == 0)
	{
	  ERROR(ENOMEM, 0);
	  result = -1;
	}
    }
  else
    {
      memset(map, 0, HFS_MAP1SZ);
      BMSET(map, 0);
    }

  ext->map     = map;
  ext->mapsz   = HFS_MAP1SZ;
  ext->flags   = HFS_UPDATE_BTHDR;
  ext->compare = r_compareextkeys;

  if (result == 0 && bt_space(ext, 1) < 0)
    result = -1;

  --ext->hdr.bthFree;

  /* create catalog file */

  cat->f.vol   = &vol;
  cat->f.parid = 0;
  strcpy(cat->f.name, "catalog");

  cat->f.cat.cdrType          = cdrFilRec;
  /* cat->f.cat.cdrResrv2 */
  cat->f.cat.u.fil.filFlags   = 0;
  cat->f.cat.u.fil.filTyp     = 0;
  /* cat->f.cat.u.fil.filUsrWds */
  cat->f.cat.u.fil.filFlNum   = HFS_CNID_CAT;
  cat->f.cat.u.fil.filStBlk   = 0;
  cat->f.cat.u.fil.filLgLen   = 0;
  cat->f.cat.u.fil.filPyLen   = 0;
  cat->f.cat.u.fil.filRStBlk  = 0;
  cat->f.cat.u.fil.filRLgLen  = 0;
  cat->f.cat.u.fil.filRPyLen  = 0;
  cat->f.cat.u.fil.filCrDat   = vol.mdb.drCrDate;
  cat->f.cat.u.fil.filMdDat   = vol.mdb.drLsMod;
  cat->f.cat.u.fil.filBkDat   = 0;
  /* cat->f.cat.u.fil.filFndrInfo */
  cat->f.cat.u.fil.filClpSize = 0;

  for (i = 0; i < 3; ++i)
    {
      cat->f.cat.u.fil.filExtRec[i].xdrStABN     = 0;
      cat->f.cat.u.fil.filExtRec[i].xdrNumABlks  = 0;

      cat->f.cat.u.fil.filRExtRec[i].xdrStABN    = 0;
      cat->f.cat.u.fil.filRExtRec[i].xdrNumABlks = 0;
    }
  /* cat->f.cat.u.fil.filResrv */
  f_selectfork(&cat->f, 0);

  cat->f.clump = vol.mdb.drCTClpSiz;
  cat->f.flags = 0;

  cat->f.prev = cat->f.next = 0;

  n_init(&cat->hdrnd, cat, ndHdrNode, 0);

  cat->hdrnd.nnum       = 0;
  cat->hdrnd.nd.ndNRecs = 3;
  cat->hdrnd.roff[1]    = 0x078;
  cat->hdrnd.roff[2]    = 0x0f8;
  cat->hdrnd.roff[3]    = 0x1f8;

  memset(HFS_NODEREC(cat->hdrnd, 1), 0, 128);

  cat->hdr.bthDepth    = 0;
  cat->hdr.bthRoot     = 0;
  cat->hdr.bthNRecs    = 0;
  cat->hdr.bthFNode    = 0;
  cat->hdr.bthLNode    = 0;
  cat->hdr.bthNodeSize = HFS_BLOCKSZ;
  cat->hdr.bthKeyLen   = 0x25;
  cat->hdr.bthNNodes   = 0;
  cat->hdr.bthFree     = 0;
  for (i = 0; i < 76; ++i)
    cat->hdr.bthResv[i] = 0;

  map = ALLOC(char, HFS_MAP1SZ);
  if (map == 0)
    {
      if (result == 0)
	{
	  ERROR(ENOMEM, 0);
	  result = -1;
	}
    }
  else
    {
      memset(map, 0, HFS_MAP1SZ);
      BMSET(map, 0);
    }

  cat->map     = map;
  cat->mapsz   = HFS_MAP1SZ;
  cat->flags   = HFS_UPDATE_BTHDR;
  cat->compare = r_comparecatkeys;

  if (result == 0 && bt_space(cat, 1) < 0)
    result = -1;

  --cat->hdr.bthFree;

  /* create root folder */

  if (result == 0 && v_newfolder(&vol, HFS_CNID_ROOTPAR, vname) < 0)
    result = -1;

  vol.mdb.drNxtCNID = 16;

  /* finish up */

  if (result == 0)
    {
      block b;

      /* write boot blocks */

      memset(&b, 0, sizeof(b));
      b_writelb(&vol, 0, &b);
      b_writelb(&vol, 1, &b);

      /* flush other disk state */

      vol.flags |= HFS_UPDATE_MDB | HFS_UPDATE_ALTMDB | HFS_UPDATE_VBM;

      if (v_flush(&vol, 1) < 0)
	result = -1;
    }

  if (
#if 0
      close(vol.fd) < 0 && 
#endif
      result == 0)
    {
      ERROR(errno, "error closing device");
      result = -1;
    }

  FREE(vol.ext.map);
  FREE(vol.cat.map);

  return result;
}