Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:30

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 2012 - .
0005  *  Krzysztof Miesowicz <krzysztof.miesowicz@gmail.com>
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <sys/stat.h>
0034 #include <stdio.h>
0035 #include <string.h>
0036 #include <unistd.h>
0037 #include <stdlib.h>
0038 #include <errno.h>
0039 #include <rtems.h>
0040 #include <fcntl.h>
0041 #include <inttypes.h>
0042 #include <rtems/error.h>
0043 #include <ctype.h>
0044 #include <rtems/libcsupport.h>
0045 
0046 #include "fstest.h"
0047 #include "fs_config.h"
0048 #include "tmacros.h"
0049 
0050 const char rtems_test_name[] = "FSFPATHCONF " FILESYSTEM;
0051 const RTEMS_TEST_STATE rtems_test_state = TEST_STATE;
0052 
0053 static void fpathconf_test(void){
0054 
0055   int rv = 0;
0056   const char *fname = "testfile.km";
0057   int fd  = -1;
0058 
0059 /* attempt to invoke fpathconf on non-existing file */
0060   rv = fpathconf(fd, _PC_LINK_MAX);
0061   printf("\nfpathconf of non-existing file give %d , expected -1",rv);
0062 
0063   if (rv == -1) {
0064     printf("\n... creating file \"%s\"\n",fname);
0065     fd = open(fname,O_WRONLY | O_CREAT | O_TRUNC,S_IREAD|S_IWRITE);
0066 
0067     if (fd < 0) {
0068       printf("*** file create failed, errno = %d(%s)\n",errno,strerror(errno));
0069     }else
0070       printf("*** file created succesfully\n");
0071 
0072 /* invoking fpathconf with request for every possible informations */
0073     rv = fpathconf(fd, _PC_LINK_MAX);
0074     printf("\nrequest with _PC_LINK_MAX return : %d",rv);
0075     rv = fpathconf(fd, _PC_MAX_CANON);
0076     printf("\nrequest with _PC_MAX_CANON return : %d",rv);
0077     rv = fpathconf(fd, _PC_MAX_INPUT);
0078     printf("\nrequest with _PC_MAX_INPUT return : %d",rv);
0079     rv = fpathconf(fd, _PC_NAME_MAX);
0080     printf("\nrequest with _PC_NAME_MAX return : %d",rv);
0081     rv = fpathconf(fd, _PC_PATH_MAX);
0082     printf("\nrequest with _PC_PATH_MAX return : %d",rv);
0083     rv = fpathconf(fd, _PC_PIPE_BUF);
0084     printf("\nrequest with _PC_PIPE_BUF return : %d",rv);
0085     rv = fpathconf(fd, _PC_CHOWN_RESTRICTED);
0086     printf("\nrequest with _PC_CHOWN_RESTRICTED return : %d",rv);
0087     rv = fpathconf(fd, _PC_NO_TRUNC);
0088     printf("\nrequest with _PC_NO_TRUNC return : %d",rv);
0089     rv = fpathconf(fd, _PC_VDISABLE);
0090     printf("\nrequest with _PC_VDISABLE return : %d",rv);
0091     rv = fpathconf(fd, _PC_ASYNC_IO);
0092     printf("\nrequest with _PC_ASYNC_IO return : %d",rv);
0093     rv = fpathconf(fd, _PC_PRIO_IO);
0094     printf("\nrequest with _PC_PRIO_IO return : %d",rv);
0095     rv = fpathconf(fd, _PC_SYNC_IO);
0096     printf("\nrequest with _PC_SYNC_IO return : %d",rv);
0097 /* invoking fpathconf with bad information requested - 255 */
0098     rv = fpathconf(fd, 255);
0099     printf("\nrequest with bad argument return : %d",rv);
0100 
0101     close(fd);
0102     fd = open("testfile.test", O_WRONLY);
0103 
0104     rv = fpathconf(fd, _PC_LINK_MAX);
0105   }
0106 }
0107 
0108 void test(void){
0109   fpathconf_test();
0110 }
0111 
0112 /* end of file */