Esempio n. 1
0
void main()
{
	struct student *creatlink();
	void printlink(struct student *head);
    void searchid(struct student *head,int m);
    struct student *insertnode(struct student *head,struct student *stud);
    struct student *deletenode(struct student *head,int m);
    struct student *sortid(struct student *head);
    void deletelink(struct student *head);
	struct student *head,*stu;
	int m;
    head=creatlink();
	printlink(head);
	printf("input the student id you want\n");
	scanf("%d",&m);
    searchid(head,m);
	printf("\n\nnow it's going to sort it\n\n");
    sortid(head);
	printlink(head);
	printf("then insert a student record\n ");
    stu=(struct student *)malloc(LEN);
    printf("intput the student's id\n");
	scanf("%d",&stu->num);
	printf("input the student's name\n");
	scanf("%s",stu->name);
	printf("input the student's score\n");
	scanf("%f",&stu->score);
    insertnode(head,stu);
    printlink(head);
    printf("now input the student you want to delete\n");
	scanf("%d",&m);
    deletenode(head,m);
    printlink(head);
    deletelink(head);
}
Esempio n. 2
0
int
aclsort(int nentries, int calcmask, aclent_t *aclbufp)
{
	aclent_t		*tp;
	unsigned int		newmask = 0;
	int			which;
	int			i;
	int			k;

	/* check validity first before sorting */
	if (aclcheck(aclbufp, nentries, &which) != 0)
		return (-1);

	/*
	 * Performance enhancement:
	 * We change entry type to sort order in the ACL, do the sorting.
	 * We then change sort order back to entry type.
	 * This makes entrycmp() very "light" and thus improves performance.
	 * Contrast to original implementation that had to find out
	 * the sorting order each time it is called.
	 */
	for (tp = aclbufp, i = 0; i < nentries; tp++, i++) {
		for (k = 1; k <= TOTAL_ENTRY_TYPES; k++) {
			if (tp->a_type == map_to_sort[k].entry_type) {
				tp->a_type = map_to_sort[k].sort_order;
				break;
			}
		}
	}

	/* typecast to remove incompatible type warning */
	qsort(aclbufp, nentries, sizeof (aclent_t),
	    (int (*)(const void *, const void *))entrycmp);

	for (tp = aclbufp, i = 0; i < nentries; tp++, i++) {
		for (k = 1; k <= TOTAL_ENTRY_TYPES; k++) {
			if (tp->a_type == map_to_sort[k].sort_order) {
				tp->a_type = map_to_sort[k].entry_type;
				break;
			}
		}
	}

	/*
	 * Start sorting id within USER and GROUP
	 * sortid() could return a pointer and entries left
	 * so that we dont have to search from the beginning
	 *  every time it calls
	 */
	sortid(aclbufp, nentries, USER);
	sortid(aclbufp, nentries, GROUP);
	sortid(aclbufp, nentries, DEF_USER);
	sortid(aclbufp, nentries, DEF_GROUP);

	/*
	 * Recalculate mask entry
	 */
	if (calcmask != 0) {
		/*
		 * At this point, ACL is valid and sorted. We may find a
		 * CLASS_OBJ entry and stop. Because of the case of minimum ACL,
		 * we still have to check till OTHER_OBJ entry is shown.
		 */
		for (tp = aclbufp; tp->a_type != OTHER_OBJ; tp++) {
			if (tp->a_type == USER || tp->a_type == GROUP ||
			    tp->a_type == GROUP_OBJ)
				newmask |= tp->a_perm;
			if (tp->a_type == CLASS_OBJ)
				break;
		}
		if (tp->a_type == CLASS_OBJ)
			tp->a_perm = (unsigned char)newmask;
	}
	return (0);
}