3
  675  * Check the validity of an ACL for a file.
  676  */
  677 int
  678 ufs_aclcheck(ap)
  679         struct vop_aclcheck_args /* {
  680                 struct vnode *vp;
  681                 acl_type_t type;
  682                 struct acl *aclp;
  683                 struct ucred *cred;
  684                 struct thread *td;
  685         } */ *ap;
  686 {
  687 
  688         if ((ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) == 0)
  689                 return (EOPNOTSUPP);
  690 
  691         if (ap->a_type == ACL_TYPE_NFS4)
  692                 return (ufs_aclcheck_nfs4(ap));
  693 
  694         return (ufs_aclcheck_posix1e(ap));
  695 }
  696 
  697 #endif /* !UFS_ACL */

This code comes from Freebsd UFS source. This function looks strange. After function name, there is a struct being defined. What's the deal? thanks

BufBills
  • 8,005
  • 12
  • 48
  • 90
  • See http://stackoverflow.com/questions/2633776/c-variable-declarations-after-function-heading-in-definition and http://stackoverflow.com/questions/3092006/function-declaration-kr-vs-ansi and http://stackoverflow.com/questions/4838493/kr-style-function-definition-problem – godfatherofpolka Apr 10 '14 at 16:08

1 Answers1

6

This is an old style of writing C functions where you could define a function like:

void foo(a)  /* Function and its arguments */
   int a; /* Define the type of the arguments */
{
  // Function body
}

What you have in your function, after removing the comments:

int ufs_aclcheck(ap)
    struct vop_aclcheck_args * ap;
{
   // Function body
}
R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • +1 at this ancient time function prototypes weren't available yet. (K&R style) – stacker Apr 10 '14 at 16:11
  • @stacker, if so, how can FreeBSD been built by using new compiler? – BufBills Apr 10 '14 at 16:16
  • 1
    @NoName this code still builds because the old style function declarations are still valid syntax in current C, precisely so that old code like this can still be compiled. The C standards committee generally avoid making changes which will break valid legacy code - the one example I can think if is the decision to get rid of gets() in C 2011. – Nigel Harper Apr 10 '14 at 16:22