示例#1
0
文件: pt_util.c 项目: bagdxk/openafs
static int
display_entry(int offset)
{
    lseek(dbase_fd, offset + HDRSIZE, L_SET);
    if (read(dbase_fd, &pre, sizeof(struct prentry)) < 0) {
	fprintf(stderr, "pt_util: error reading entry %d: %s\n",
		offset, strerror(errno));
	exit(1);
    }

    fix_pre(&pre);

    if ((pre.flags & PRFREE) == 0) {
	if (pre.flags & PRGRP) {
	    if (flags & DO_GRP)
		add_group(pre.id);
	} else {
	    if (print_id(pre.id) && (flags & DO_USR))
		fprintf(dfp, FMT_BASE, pre.name, pre.flags, pre.ngroups,
			pre.id, pre.owner, pre.creator);
	    checkin(&pre);
	}
    }
    return (nflag ? pre.nextName : pre.nextID);
}
示例#2
0
文件: pt_util.c 项目: bagdxk/openafs
static char *
id_to_name(int id)
{
    int offset;
    static struct prentry pre;
    char *name;

    name = check_core(id);
    if (name)
	return (name);
    offset = ntohl(prh.idHash[IDHash(id)]);
    while (offset) {
	lseek(dbase_fd, offset + HDRSIZE, L_SET);
	if (read(dbase_fd, &pre, sizeof(struct prentry)) < 0) {
	    fprintf(stderr, "pt_util: read i/o error: %s\n", strerror(errno));
	    exit(1);
	}
	pre.id = ntohl(pre.id);
	if (pre.id == id) {
	    name = checkin(&pre);
	    return (name);
	}
	offset = ntohl(pre.nextID);
    }
    return 0;
}
示例#3
0
char* TSolver::convert()  //converts function names to symbols
{if ((S==NULL || !strlen(S)) || !checkin() || !checkbr())
  {seterr(E_VOID);if(S!=NULL)free(S);return NULL;}
 char* p;
 int i,j;
 int sl;
 int SL=strlen(S);
 Err=E_NO;
 for (i=0;i<=SL;i++)
   if (S[i]==' ')
    {for (j=i;j<=SL+1;j++)
       S[j]=S[j+1];
     SL--;
    }
 for (i=NFUNC-1;i>=0;i--)
   while ((p=strstr(S,SLex[i]))!=NULL)
     {S[p-S]=cpi+i;
      sl=strlen(SLex[i])-1;
      SL-=sl;
      for (j=p-S+1;j<=SL;j++)
	S[j]=S[j+sl];
     }
 for (i=0;i<SL;i++)
   if (S[i]=='-' && (minusF))
     S[i]='_';
#ifdef debug
 printf("%s\n",S);
#endif
 if (!checkout() || !checkexpr()) {converted=good=0;return NULL;}
 converted=good=1;
 return S;
}
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  find_waters
 *  Description:  返回出现超过1/4的三个数字
 * =====================================================================================
 */
TribleWater find_waters(int arr[], int n)
{
    TribleWater res;
    memset(&res, 0, sizeof(res));

    if(n < 3) return res;

    int i;
    for(i = 0;i < n;i++)
    {
        if(!checkin(&res, arr[i]))
        {
            res.count[0]--;
            res.count[1]--;
            res.count[2]--;
        }
    }

    return res;
}
示例#5
0
int main() {
	int n;
	char cn[20];
	list l;
	customer c;
	date d1, d2;
	printf("Welcome to hotel GRAND :\n");
	printf("Total rooms in hotel are: 500\n");
	printf("Single rooms are: 300\nDouble rooms are: 200");
	printf("Cost for one day:\nSingle room stay is:'350'\nDouble room stay is:'600'\n");
	while(1) {
		n = options();
		switch(n) {
			case 1:
				cs_info(&c);
				printf("Entry Date:\n");
				date_info(&d1);
				printf("Exit Date:\n");
				date_info(&d2);
				checkin(&l, &c, &d1, &d2);
				traverse(&l);
				break;
			case 2:
				printf("Enter the name of Customer who want to Checkout\n");
				scanf("%s", cn);
				checkout(&l, &c, &d1, &d2, cn);
				traverse(&l);
				break;
			case 3:
				total_bill(&c, &d1, &d2);
				printf("Your total bill is:%d\n",c.total_bill);
				break;
			case 4:
				rooms();
				break;
			default:
				printf("SORRY we don't get you\nPlease enter the valid option\n");
		}
	}
	return 0;
}
示例#6
0
static int
display_entry(int offset)
{
    lseek(dbase_fd, offset + HDRSIZE, L_SET);
    read(dbase_fd, &pre, sizeof(struct prentry));

    fix_pre(&pre);

    if ((pre.flags & PRFREE) == 0) {
	if (pre.flags & PRGRP) {
	    if (flags & DO_GRP)
		add_group(pre.id);
	} else {
	    if (print_id(pre.id) && (flags & DO_USR))
		fprintf(dfp, FMT_BASE, pre.name, pre.flags, pre.ngroups,
			pre.id, pre.owner, pre.creator);
	    checkin(&pre);
	}
    }
    return (nflag ? pre.nextName : pre.nextID);
}
int main(int ac, char *av[])
	{
	char *p = NULL;
	kern_return_t kr = KERN_FAILURE;
	long n;
	int ch;
	mach_msg_header_t hdr;

	while ((ch = getopt(ac, av, "dt:")) != -1)
		switch (ch)
		{
		case 'd': opt_debug = 1; break;
		case 't':
			n = strtol(optarg, &p, 0);
			if ('\0' == optarg[0] || '\0' != *p || n > LONG_MAX || n < 0)
				{ fprintf(stderr, "Invalid idle timeout: %s\n", optarg); exit(EXIT_FAILURE); }
			maxidle = n;
			break;
		case '?':
		default:
			fprintf(stderr, "Usage: mDNSResponderHelper [-d] [-t maxidle]\n");
			exit(EXIT_FAILURE);
		}
	ac -= optind;
	av += optind;

	initialize_logging();
	helplog(ASL_LEVEL_INFO, "Starting");
	initialize_id();

#ifndef NO_SECURITYFRAMEWORK
	// We should normally be running as a system daemon.  However, that might not be the case in some scenarios (e.g. debugging).
	// Explicitly ensure that our Keychain operations utilize the system domain.
	if (opt_debug) SecKeychainSetPreferenceDomain(kSecPreferencesDomainSystem);
#endif
	gPort = checkin(kmDNSHelperServiceName);
	if (!gPort)
		{
		helplog(ASL_LEVEL_ERR, "Launchd provided no launchdata; will open Mach port explicitly");
		gPort = register_service(kmDNSHelperServiceName);
		}

	if (maxidle) actualidle = maxidle;

	signal(SIGTERM, handle_sigterm);

	if (initialize_timer()) exit(EXIT_FAILURE);
	for (n=0; n<100000; n++) if (!gRunLoop) usleep(100);
	if (!gRunLoop)
		{
		helplog(ASL_LEVEL_ERR, "gRunLoop not set after waiting");
		exit(EXIT_FAILURE);
		}

	for(;;)
		{
		hdr.msgh_bits = 0;
		hdr.msgh_local_port = gPort;
		hdr.msgh_remote_port = MACH_PORT_NULL;
		hdr.msgh_size = sizeof(hdr);
		hdr.msgh_id = 0;
		kr = mach_msg(&hdr, MACH_RCV_LARGE | MACH_RCV_MSG, 0, hdr.msgh_size, gPort, 0, 0);
		if (MACH_RCV_TOO_LARGE != kr) helplog(ASL_LEVEL_ERR, "kr: %d: %s", kr, mach_error_string(kr));
		
		safe_vproc_transaction_begin();
		
		kr = mach_msg_server_once(helper_server, MAX_MSG_SIZE, gPort,
			MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT) | MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0));
		if (KERN_SUCCESS != kr)
			{ helplog(ASL_LEVEL_ERR, "mach_msg_server: %s\n", mach_error_string(kr)); exit(EXIT_FAILURE); }
		
		safe_vproc_transaction_end();
		}
	exit(EXIT_SUCCESS);
	}