Replace gets() calls into fgets(),

This commit is contained in:
agibert 2005-02-23 23:34:48 +00:00
parent 8e908f867c
commit 1f4d73bc70

View File

@ -3,10 +3,14 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <node.h> #include <node.h>
#define SM_MODE 0 /* Utilisation des API sécurisés */
#ifndef SM_MODE
# define SM_MODE 0 /* Utilisation des API sécurisés */
#endif
#include <shmem.h> #include <shmem.h>
//VER_INFO_EXPORT (smadmin, "$Revision: 2.1 $", "$Name: $", __FILE__, "$Author: agibert $") //VER_INFO_EXPORT (smadmin, "$Revision: 2.2 $", "$Name: $", __FILE__, "$Author: agibert $")
#define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n" #define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n"
@ -30,8 +34,15 @@
#define ACR_DUMP 17 #define ACR_DUMP 17
#define FCR_DUMP 18 #define FCR_DUMP 18
#define NAME_LEN 100
#define NAME_SIZE ( NAME_LEN + 1)
#define TMP_LEN 100
#define TMP_SIZE ( TMP_LEN + 1)
char menu [1000]; char menu [1000];
char tmp [100];
char tmp [TMP_SIZE];
void init_menu (void); void init_menu (void);
int print_menu (void); int print_menu (void);
@ -39,7 +50,7 @@ int print_menu (void);
int main (int argc, char ** argv) int main (int argc, char ** argv)
{ {
int choice; int choice;
char name [100]; char name [NAME_SIZE];
int Mode, Locked; int Mode, Locked;
void * ptr; void * ptr;
char answer [10]; char answer [10];
@ -127,9 +138,13 @@ int main (int argc, char ** argv)
case MHH_INIT: case MHH_INIT:
fprintf (stdout, "\nNew heap name ? "); fprintf (stdout, "\nNew heap name ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nHeap segment size ? "); fprintf (stdout, "\nHeap segment size ? ");
gets (tmp); fgets( tmp, NAME_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
size = atoi (tmp); size = atoi (tmp);
fprintf (stdout, "\nReturn code = %s\n", \ fprintf (stdout, "\nReturn code = %s\n", \
SM_Heap_Open (name, &Heap, size, \ SM_Heap_Open (name, &Heap, size, \
@ -138,9 +153,13 @@ int main (int argc, char ** argv)
case MHH_OPEN: case MHH_OPEN:
fprintf (stdout, "\nHeap name to open ? "); fprintf (stdout, "\nHeap name to open ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nOpening mode (read=1 write=2) ? "); fprintf (stdout, "\nOpening mode (read=1 write=2) ? ");
gets (tmp); fgets( tmp, TMP_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
if (tmp[0] == '1') Mode = SMD_READ; if (tmp[0] == '1') Mode = SMD_READ;
else Mode = SMD_WRITE; else Mode = SMD_WRITE;
if (!strcmp (name, HEAP_SYSTEM)) if (!strcmp (name, HEAP_SYSTEM))
@ -157,7 +176,9 @@ int main (int argc, char ** argv)
case MHH_COMPRESS: case MHH_COMPRESS:
fprintf (stdout, "\nHeap name à compresser ? "); fprintf (stdout, "\nHeap name à compresser ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
size_t Compress; size_t Compress;
@ -169,7 +190,9 @@ int main (int argc, char ** argv)
case MHH_END: case MHH_END:
fprintf (stdout, "\nHeap name to remove ? "); fprintf (stdout, "\nHeap name to remove ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
if (!strcmp (name, HEAP_SYSTEM)) if (!strcmp (name, HEAP_SYSTEM))
{ {
fprintf (stdout, \ fprintf (stdout, \
@ -184,7 +207,9 @@ int main (int argc, char ** argv)
case MHH_CLOSE: case MHH_CLOSE:
fprintf (stdout, "\nHeap name to close ? "); fprintf (stdout, "\nHeap name to close ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
if (!strcmp (name, HEAP_SYSTEM)) if (!strcmp (name, HEAP_SYSTEM))
{ {
fprintf (stdout, \ fprintf (stdout, \
@ -201,7 +226,9 @@ int main (int argc, char ** argv)
case MHH_CHECK: case MHH_CHECK:
fprintf (stdout, "\nHeap name to check/recover ? "); fprintf (stdout, "\nHeap name to check/recover ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
Nb_Detected = Nb_Corrected = 0; Nb_Detected = Nb_Corrected = 0;
@ -212,9 +239,13 @@ int main (int argc, char ** argv)
case ALLOC_CHUNK: case ALLOC_CHUNK:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nAllocation size ? "); fprintf (stdout, "\nAllocation size ? ");
gets (tmp); fgets( tmp, TMP_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
size = atoi (tmp); size = atoi (tmp);
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
@ -226,26 +257,36 @@ int main (int argc, char ** argv)
case WRITE_CHUNK: case WRITE_CHUNK:
fprintf (stdout, "\nAddress ? "); fprintf (stdout, "\nAddress ? ");
gets (tmp); fgets( tmp, TMP_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
ptr = (void *)atoi (tmp); ptr = (void *)atoi (tmp);
fprintf (stdout, "\nString to put in ? "); fprintf (stdout, "\nString to put in ? ");
gets (tmp); fgets( tmp, TMP_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
strcpy ( (char *)ptr, tmp); strcpy ( (char *)ptr, tmp);
fprintf (stdout, "\nOK\n"); fprintf (stdout, "\nOK\n");
break; break;
case READ_CHUNK: case READ_CHUNK:
fprintf (stdout, "\nAddress ? "); fprintf (stdout, "\nAddress ? ");
gets (tmp); fgets( tmp, TMP_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
ptr = (void *)atoi (tmp); ptr = (void *)atoi (tmp);
fprintf (stdout, "\nValeur du pointeur = %s\n", (char *)ptr); fprintf (stdout, "\nValeur du pointeur = %s\n", (char *)ptr);
break; break;
case FREE_CHUNK: case FREE_CHUNK:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nAddress ? "); fprintf (stdout, "\nAddress ? ");
gets (tmp); fgets( tmp, TMP_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
ptr = (void *)atoi (tmp); ptr = (void *)atoi (tmp);
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
@ -258,7 +299,9 @@ int main (int argc, char ** argv)
case DSR_DUMP: case DSR_DUMP:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
{ {
ND_DataStruct_Info_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); ND_DataStruct_Info_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
@ -269,7 +312,9 @@ int main (int argc, char ** argv)
case ACR_DUMP: case ACR_DUMP:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
{ {
ND_DataStruct_Info_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); ND_DataStruct_Info_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
@ -280,7 +325,9 @@ int main (int argc, char ** argv)
case FCR_DUMP: case FCR_DUMP:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
gets (name); fgets( name, NAME_SIZE, stdin);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
{ {
ND_DataStruct_Info_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); ND_DataStruct_Info_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
@ -333,7 +380,9 @@ int print_menu (void)
while (tmp[0] == '\0') while (tmp[0] == '\0')
{ {
printf ("\nChoice ? "); printf ("\nChoice ? ");
gets (tmp); fgets( tmp, TMP_SIZE, stdin);
tmp[ strlen( tmp) - 1] = '\0';
} }
return atoi (tmp); return atoi (tmp);