From: =?utf-8?b?0L3QsNCx?= Date: Sat, 1 Mar 2025 19:13:27 +0100 Subject: Port to GCC-15 (Closes: #1096398) --- buffer.c | 58 +++++++++++++++++++++++++--------------------------------- sem.c | 34 +++++++++++----------------------- sem.h | 10 +++++----- 3 files changed, 41 insertions(+), 61 deletions(-) diff --git a/buffer.c b/buffer.c index e6b5571..c48a6a3 100644 --- a/buffer.c +++ b/buffer.c @@ -87,27 +87,27 @@ * * Revision 1.5 90/07/22 18:46:38 lmjm * Added system 5 support. - * + * * Revision 1.4 90/07/22 18:29:48 lmjm * Updated arg handling to be more consistent. * Make sofar printing size an option. - * + * * Revision 1.3 90/05/15 23:27:46 lmjm * Added -S option (show how much has been written). * Added -m option to specify how much shared memory to grab. * Now tries to fill this with blocks. * reader waits for writer to terminate and then frees the shared mem and sems. - * + * * Revision 1.2 90/01/20 21:37:59 lmjm * Reset default number of blocks and blocksize for best thruput of * standard tar 10K Allow. * blocks number of blocks to be changed. * Don't need a hole in the circular queue since the semaphores prevent block * clash. - * + * * Revision 1.1 90/01/17 11:30:23 lmjm * Initial revision - * + * */ #include #include @@ -149,13 +149,13 @@ extern char *shmat(); #endif /* Some forward declarations */ -void byee(); +void byee(int); void start_reader_and_writer(); -void parse_args(); +void parse_args( int argc, char **argv ); void set_handlers(); void buffer_allocate(); void report_proc(); -int do_size(); +int do_size( char *arg ); void get_buffer(); void reader(); void writer(); @@ -166,7 +166,7 @@ void test_writer(); int fill_block(); void get_next_filled_block(); int data_to_write(); -void write_blocks_to_stdout(); +void write_blocks_to_stdout( int filled, int first_block ); void write_block_to_stdout(); void pr_out(); void end_writer(); @@ -200,7 +200,7 @@ int blocksize = DEF_BLOCKSIZE; /* Which process... in error reports*/ char *proc_string = "buffer"; -/* Numbers of blocks in the queue. +/* Numbers of blocks in the queue. */ #define MAX_BLOCKS 2048 int blocks = 1; @@ -267,16 +267,14 @@ NUM_K_TYPE outk = 0; struct timeval starttime; int -main( argc, argv ) - int argc; - char **argv; +main( int argc, char **argv ) { parse_args( argc, argv ); set_handlers(); buffer_allocate(); - + gettimeofday(&starttime, NULL); start_reader_and_writer(); @@ -288,9 +286,7 @@ main( argc, argv ) } void -parse_args( argc, argv ) - int argc; - char **argv; +parse_args( int argc, char **argv ) { int c; int iflag = 0; @@ -415,7 +411,7 @@ parse_args( argc, argv ) byee( -1 ); } } - + if (argc > optind) { fprintf( stderr, "too many arguments\n" ); byee( -1 ); @@ -453,7 +449,7 @@ parse_args( argc, argv ) /* The interrupt handler */ void -shutdown() +shutdown( int _ ) { static int shutting; if( shutting ){ @@ -470,7 +466,7 @@ shutdown() /* Shutdown because the child has ended */ void -child_shutdown() +child_shutdown( int _ ) { /* Find out which child has died. (They may not be my * children if buffer was exec'd on top of something that had @@ -556,13 +552,13 @@ buffer_allocate() * level. However, there doesn't seem to be a good reason to keep one block free, * so we initialize the semaphore to "blocks" instead. * 2004-01-11 - */ + */ #if 0 sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks - 1 ); #else sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks ); #endif - + /* Do not detach the shared memory, but leave it mapped. It will be inherited * over fork just fine and this ensures that it's mapped at the same address * both in the reader and writer. The original code did a shmdt() here followed @@ -600,7 +596,7 @@ buffer_remove() if( debug ) fprintf( stderr, "%s: removing semaphores and buffer\n", proc_string ); remove_sems( pbuffer->semid ); - + if( shmctl( buffer_id, IPC_RMID, (struct shmid_ds *)0 ) == -1 ){ report_proc(); perror( "failed to remove shared memory buffer" ); @@ -693,7 +689,7 @@ fill_block() char *start; int toread; static char eof_reached = 0; - + if( eof_reached ){ curr_block->bytes = 0; unlock( pbuffer->semid, pbuffer->blocks_used_lock ); @@ -806,9 +802,7 @@ data_to_write() } void -write_blocks_to_stdout( filled, first_block ) - int filled; - int first_block; +write_blocks_to_stdout( int filled, int first_block ) { pbuffer->next_block_out = first_block; @@ -877,8 +871,7 @@ write_block_to_stdout() void -byee( exit_val ) - int exit_val; +byee( int exit_val ) { if( writer_pid != 0 ){ if( exit_val != 0 ){ @@ -950,8 +943,7 @@ test_writer() * b/B for 512 */ int -do_size( arg ) - char *arg; +do_size( char *arg ) { int ret = 0; @@ -972,7 +964,7 @@ do_size( arg ) ret *= 512; break; } - + return ret; } @@ -981,7 +973,7 @@ pr_out() { struct timeval now; unsigned long ms_delta, k_per_s; - + gettimeofday(&now, NULL); ms_delta = (now.tv_sec - starttime.tv_sec) * 1000 + (now.tv_usec - starttime.tv_usec) / 1000; diff --git a/sem.c b/sem.c index 69e6a7d..b495f46 100644 --- a/sem.c +++ b/sem.c @@ -56,7 +56,7 @@ union semun { ushort *array; }; #endif -#endif +#endif /* IMPORTS */ @@ -64,17 +64,14 @@ union semun { extern void report_proc(); /* Used to end the program - on error */ -extern void byee(); +extern void byee(int); /* Set a semaphore to a particular value - meant to be used before * first lock/unlock */ void -sem_set( sem_id, semn, val ) - int sem_id; - int semn; - int val; +sem_set( int sem_id, int semn, int val ) { union semun arg; extern int errno; @@ -89,21 +86,20 @@ sem_set( sem_id, semn, val ) byee( -1 ); } } - + int -new_sems( nsems ) - int nsems; +new_sems( int nsems ) { int sem; int i; - sem = semget( IPC_PRIVATE, nsems, IPC_CREAT|S_IREAD|S_IWRITE ); + sem = semget( IPC_PRIVATE, nsems, IPC_CREAT|0600 ); if( sem < 0 ){ report_proc(); perror( "internal error, couldn't create semaphore" ); byee( -1 ); } - + for( i = 0; i < nsems; i++ ){ sem_set( sem, i, 1 ); } @@ -112,10 +108,7 @@ new_sems( nsems ) } static void -do_sem( sem_id, pbuf, err ) - int sem_id; - struct sembuf *pbuf; - char *err; +do_sem( int sem_id, struct sembuf *pbuf, char *err ) { /* This just keeps us going in case of EINTR */ while( 1 ){ @@ -134,9 +127,7 @@ do_sem( sem_id, pbuf, err ) } void -lock( sem_id, semn ) - int sem_id; - int semn; +lock( int sem_id, int semn ) { struct sembuf sembuf; @@ -148,9 +139,7 @@ lock( sem_id, semn ) } void -unlock( sem_id, semn ) - int sem_id; - int semn; +unlock( int sem_id, int semn ) { struct sembuf sembuf; @@ -162,8 +151,7 @@ unlock( sem_id, semn ) } void -remove_sems( sem_id ) - int sem_id; +remove_sems( int sem_id ) { union semun arg; diff --git a/sem.h b/sem.h index 9004f95..c61fb95 100644 --- a/sem.h +++ b/sem.h @@ -27,10 +27,10 @@ * semaphores */ /* Allocate new semaphores */ -int new_sems(); +int new_sems(int nsems); /* Perform actions on semaphores */ -void sem_set(); -void lock(); -void unlock(); -void remove_sems(); +void sem_set(int sem_id, int semn, int val); +void lock(int sem_id, int semn); +void unlock(int sem_id, int semn); +void remove_sems(int sem_id);