2015-12-17 17:56:48 +00:00
/*
2016-11-29 04:08:47 +00:00
* Check decoding of utime syscall .
2016-02-06 00:56:55 +00:00
*
2016-01-04 23:58:19 +00:00
* Copyright ( c ) 2015 - 2016 Dmitry V . Levin < ldv @ altlinux . org >
2015-12-17 17:56:48 +00:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2016-01-04 23:58:19 +00:00
# include "tests.h"
2016-11-28 12:44:54 +03:00
# include <asm/unistd.h>
2015-07-15 09:02:17 +00:00
2016-11-29 04:08:47 +00:00
# ifdef __NR_utime
# include <time.h>
# include <utime.h>
# include <errno.h>
# include <stdio.h>
# include <unistd.h>
static long
k_utime ( const void * const filename , const void * const times )
{
return syscall ( __NR_utime , filename , times ) ;
}
2015-07-15 09:02:17 +00:00
int
main ( void )
{
2016-11-29 04:08:47 +00:00
static const char * const dummy_str = " dummy filename " ;
2016-02-06 00:56:55 +00:00
2017-04-16 17:28:00 +00:00
const time_t t = 1492350678 ;
2016-02-06 00:56:55 +00:00
const struct utimbuf u = { . actime = t , . modtime = t } ;
2017-02-12 19:14:15 +00:00
const struct utimbuf * const tail_u = tail_memdup ( & u , sizeof ( u ) ) ;
2016-11-29 04:08:47 +00:00
const char * const dummy_filename =
2016-11-28 12:44:54 +03:00
tail_memdup ( dummy_str , sizeof ( dummy_str ) - 1 ) ;
2016-11-29 04:08:47 +00:00
long rc = k_utime ( " " , NULL ) ;
printf ( " utime( \" \" , NULL) = %s \n " , sprintrc ( rc ) ) ;
rc = k_utime ( dummy_filename + sizeof ( dummy_str ) , tail_u + 1 ) ;
2016-11-28 12:44:54 +03:00
printf ( " utime(%p, %p) = %s \n " , dummy_filename + sizeof ( dummy_str ) ,
tail_u + 1 , sprintrc ( rc ) ) ;
2016-11-29 04:08:47 +00:00
rc = k_utime ( dummy_filename , ( struct tm * ) tail_u + 1 ) ;
2016-11-28 12:44:54 +03:00
printf ( " utime(%p, %p) = %s \n " ,
dummy_filename , ( struct tm * ) tail_u + 1 , sprintrc ( rc ) ) ;
2016-11-29 04:08:47 +00:00
rc = k_utime ( " utime \n filename " , tail_u ) ;
2016-09-19 19:49:59 +00:00
const char * errstr = sprintrc ( rc ) ;
2016-11-28 12:26:13 +03:00
printf ( " utime( \" utime \\ nfilename \" , {actime= " ) ;
2017-02-26 23:23:31 +00:00
print_time_t_nsec ( t , 0 ) ;
2016-11-28 12:26:13 +03:00
printf ( " , modtime= " ) ;
2017-02-26 23:23:31 +00:00
print_time_t_nsec ( t , 0 ) ;
2016-11-28 12:26:13 +03:00
printf ( " }) = %s \n " , errstr ) ;
2016-09-19 19:49:59 +00:00
2015-08-26 23:25:06 +00:00
puts ( " +++ exited with 0 +++ " ) ;
2016-01-04 23:58:19 +00:00
return 0 ;
2015-07-15 09:02:17 +00:00
}
2016-11-29 04:08:47 +00:00
# else
SKIP_MAIN_UNDEFINED ( " __NR_utime " )
# endif