Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macports-legacy-support
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
einsteinathome
openjdk
macports-legacy-support
Commits
b9309fc8
Commit
b9309fc8
authored
10 months ago
by
raf
Committed by
Christopher Nielsen
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for fgetattrlist() and fsetattrlist()
parent
af8a73fc
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
manual_tests/darwin_c.c
+1
-0
1 addition, 0 deletions
manual_tests/darwin_c.c
test/test_fgetattrlist.c
+68
-0
68 additions, 0 deletions
test/test_fgetattrlist.c
test/test_fsetattrlist.c
+95
-0
95 additions, 0 deletions
test/test_fsetattrlist.c
with
164 additions
and
0 deletions
manual_tests/darwin_c.c
+
1
−
0
View file @
b9309fc8
...
...
@@ -212,6 +212,7 @@ int timespec_get = 0;
#ifdef _SC_PHYS_PAGES
#error _SC_PHYS_PAGES is unexpectedly defined
#endif
int
fgetattrlist
=
0
;
int
fsetattrlist
=
0
;
#endif
/* __DARWIN_C_LEVEL < __DARWIN_C_FULL */
...
...
This diff is collapsed.
Click to expand it.
test/test_fgetattrlist.c
0 → 100644
+
68
−
0
View file @
b9309fc8
/*
* Copyright (C) 2024 raf <raf@raf.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* Based on the first example in the getattrlist(2) manual entry */
#include
<assert.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#include
<fcntl.h>
#include
<unistd.h>
#include
<sys/attr.h>
#include
<sys/errno.h>
#include
<sys/vnode.h>
typedef
struct
attrlist
attrlist_t
;
struct
FInfoAttrBuf
{
u_int32_t
length
;
fsobj_type_t
objType
;
char
finderInfo
[
32
];
}
__attribute__
((
aligned
(
4
),
packed
));
typedef
struct
FInfoAttrBuf
FInfoAttrBuf
;
static
int
FInfoDemo
(
int
fd
)
{
int
err
;
attrlist_t
attrList
;
FInfoAttrBuf
attrBuf
;
memset
(
&
attrList
,
0
,
sizeof
(
attrList
));
attrList
.
bitmapcount
=
ATTR_BIT_MAP_COUNT
;
attrList
.
commonattr
=
ATTR_CMN_OBJTYPE
|
ATTR_CMN_FNDRINFO
;
err
=
fgetattrlist
(
fd
,
&
attrList
,
&
attrBuf
,
sizeof
(
attrBuf
),
0
);
if
(
err
!=
0
)
err
=
errno
;
if
(
err
==
0
)
assert
(
attrBuf
.
length
==
sizeof
(
attrBuf
));
return
err
;
}
/* Note: Not an exhaustive test. Just call fgetattrlist(). */
int
main
(
int
ac
,
char
**
av
)
{
int
rc
=
(
FInfoDemo
(
open
(
"."
,
O_RDONLY
))
==
0
)
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
if
(
rc
!=
EXIT_SUCCESS
)
printf
(
"fgetattrlist() failed, possibly correctly due to an unexpected filesystem type
\n
"
);
return
rc
;
}
/* vi:set et ts=4 sw=4: */
This diff is collapsed.
Click to expand it.
test/test_fsetattrlist.c
0 → 100644
+
95
−
0
View file @
b9309fc8
/*
* Copyright (C) 2024 raf <raf@raf.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* Based on the first example in the getattrlist(2) manual entry */
#include
<assert.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<stddef.h>
#include
<string.h>
#include
<fcntl.h>
#include
<sys/attr.h>
#include
<sys/errno.h>
#include
<unistd.h>
#include
<sys/vnode.h>
typedef
struct
attrlist
attrlist_t
;
struct
FInfoAttrBuf
{
u_int32_t
length
;
fsobj_type_t
objType
;
char
finderInfo
[
32
];
};
typedef
struct
FInfoAttrBuf
FInfoAttrBuf
;
static
int
FInfoDemo
(
int
fd
,
const
char
*
type
,
const
char
*
creator
)
{
int
err
;
attrlist_t
attrList
;
FInfoAttrBuf
attrBuf
;
assert
(
strlen
(
type
)
==
4
);
assert
(
strlen
(
creator
)
==
4
);
memset
(
&
attrList
,
0
,
sizeof
(
attrList
));
attrList
.
bitmapcount
=
ATTR_BIT_MAP_COUNT
;
attrList
.
commonattr
=
ATTR_CMN_OBJTYPE
|
ATTR_CMN_FNDRINFO
;
err
=
fgetattrlist
(
fd
,
&
attrList
,
&
attrBuf
,
sizeof
(
attrBuf
),
0
);
if
(
err
!=
0
)
{
err
=
errno
;
}
if
((
err
==
0
)
&&
(
attrBuf
.
objType
!=
VREG
))
{
fprintf
(
stderr
,
"Not a standard file."
);
err
=
EINVAL
;
}
else
{
memcpy
(
&
attrBuf
.
finderInfo
[
0
],
type
,
4
);
memcpy
(
&
attrBuf
.
finderInfo
[
4
],
creator
,
4
);
attrList
.
commonattr
=
ATTR_CMN_FNDRINFO
;
err
=
fsetattrlist
(
fd
,
&
attrList
,
attrBuf
.
finderInfo
,
sizeof
(
attrBuf
.
finderInfo
),
0
);
}
return
err
;
}
/* Note: Not an exhaustive test. Just call fsetattrlist(). */
int
main
(
int
ac
,
char
**
av
)
{
const
char
*
fname
=
"./.jnk.tmp"
;
int
fd
=
open
(
fname
,
O_CREAT
|
O_RDWR
,
S_IRWXU
);
int
rc
=
(
FInfoDemo
(
fd
,
"TYPE"
,
"CRTR"
)
==
0
)
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
unlink
(
fname
);
if
(
rc
!=
EXIT_SUCCESS
)
printf
(
"fgetattrlist() failed, possibly correctly due to an unexpected filesystem type
\n
"
);
return
rc
;
}
/* vi:set et ts=4 sw=4: */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment