Ustun ERGENOGLU wrote:
nasıl kullandığınızı belirtirseniz, yardımcı olacak birileri çıkabilir.
üstün
09.01.2008 tarihinde YILDIRIM <linux@isadamlari.org> yazmış:
Linux altında gcc kullanarak derleme yaptığımda string.h kütüphanesinde
bulunan gets(), strcmp() gibi string fonksiyonlarından kaynaklanan
"segmentation fault" hataları alıyorum. Bu problemi çözmenin bir yolu
var mıdır?
Şimdiden yardımcı olan arkadaşlara teşekkür ederim.
Mehmet Salih YILDIRIM
_______________________________________________
Linux-programlama mailing list
Linux-programlama@liste.linux.org.tr
http://liste.linux.org.tr/mailman/listinfo/linux-programlama
_______________________________________________
Linux-programlama mailing list
Linux-programlama@liste.linux.org.tr
http://liste.linux.org.tr/mailman/listinfo/linux-programlama
Aşağıda bi programın şablonu olarak hazırladığım kodlar bulunmakta.
Arkadaşım windows altında bir derleyiciyle (dev c) derlediğinde
sorunsuz çalışıyor. Fakat Linux altında gcc ile derlediğimde derleme
başarılı oluyor fakat "help" komutu gibi komutları verdiğimde
"segmentation fault" verip programı sonlandırıyor. Sorunun string.h
kütüphanesindeki fonksiyonlardan kaynaklandığını düşünüyorum. İlgilenen
herkese teşekkür ederim.
Mehmet Salih YILDIRIM
<code>
// prevent program crash when using commands with no
parameters or with not expected value of parameters //
// for whoami and logout it is not necacery to define them
as a "program" //
// ANA PROGRAM //
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
static char actvusr[20]="testuser";
int main () {
char pathp[20];
char param2[20];
char param1[20];
char cmd[20];
char comand[20];
int i,j,k;
printf("\n\n\n Welcome FS-1a \n");
printf("\n by A.Egitmen & M.S.Yildirim\n\n\n");
printf("\n For instructions type 'help'\n\n\n");
do {
printf("/%s>",actvusr);
gets(comand);
i=0;
j=0;
k=0;
while(comand[i]!=32){
cmd[i]=comand[i];
i++;
}
cmd[i]='\0';
i++;
//______________________________________________________________________________________________________________
/*help*/ if(!strcmp(cmd,"help")){
printf("\n Login Usage : login
'username'\n ");
printf("\n Dir Usage : dir
'pathname'\n");
printf("\n Copy Usage : cp
'source''FILENAME' 'destination''FILENAME'\n");
printf("\n Delete Usage : del
'source2''FILENAME'\n");
printf("\n ReaderList Usage : rl\n" );
printf("\n Receive Usage : receive
'FILENAME'\n");
printf("\n Send Usage : send
'FILENAME' 'USERNAME'\n");
printf("\n Whoami Usage : whoami\n");
printf("\n Setpass Usage : setp\n");
printf("\n Logout Usage : logout\n");
printf("\n Exit Usage :
exit\n");
}
//_____________________________________________________________________________________________________________
/*login*/ else if(!strcmp(cmd,"login")){
if(strcmp(actvusr,"\0")){
printf("\n You Have Already Logged \n");
}
else{
while(comand[i]!=32){
param1[j]=comand[i];
i++;
j++;
}
param1[j]='\0';
printf("\n command : %s\n",cmd );
printf("\n param1 : %s\n",param1);
// - login call - if pass match return =>
actvuser=username
// write system date to lastlogin.txt
// find username from actvuser.dat and write 1 to
there
// you will rechange it to 0 when logout
}
}
//___________________________________________________________________________________________________________
/*dir*/ else if(!strcmp(cmd,"dir")){
if(!strcmp(actvusr,"\0")){
printf("\n Please Login Before Using
Commands\n");
}
else{
while(comand[i]!=32){
param1[j]=comand[i];
i++;
j++;
}
param1[j]='\0';
printf("\n command : %s\n",cmd );
printf("\n param1 :
%s\n",param1);
// call dir , print files while in dir; return
void
}
}
//_____________________________________________________________________________________________________________
/*COPY*/ else if(!strcmp(cmd,"cp")){
if(!strcmp(actvusr,"\0")){
printf("\n Please Login Before Using
Commands\n");
}
else{
while(comand[i]!=32){
param1[j]=comand[i];
i++;
j++;
}
param1[j]='\0';
i++;
while(comand[i]!=32){
param2[k]=comand[i];
i++;
k++;
}
param2[k]='\0';
printf("\n command : %s\n",cmd );
printf("\n param1 : %s\n",param1);
printf("\n param2 : %s\n",param2);
i=0;
while(param1[i]!=47){
pathp[i]=param1[i];
i++;
}
pathp[i]='\0';
printf("\n path : %s\n",pathp);
//get user id from uid ; with uid get supervisor
information from users.dat
//if ok then call cp
//if not get read permision for pathp from
permis.txt
//if ok call cp ;
//if not cancel it
//--call cp-- return
nothing//
}
}
//_____________________________________________________________________________________________________________
/*DELETE*/ else if(!strcmp(cmd,"del")){
if(!strcmp(actvusr,"\0")){
printf("\n Please Login Before Using
Commands\n");
}
else{
while(comand[i]!=32){
param1[j]=comand[i];
i++;
j++;
}
param1[j]='\0';
printf("\n command : %s\n",cmd );
printf("\n param1 : %s\n",param1);
while(param1[i]!=47){
pathp[i]=param1[i];
i++;
}
pathp[i]='\0';
printf("\n path : %s\n",pathp);
//get user id from uid ; with uid get supervisor
information from users.dat
//if ok then call del
//if not get read permision for pathp from
permis.txt
//if ok call del ;
//if not cancel it
//--call del-- return
nothing//
}
}
//_____________________________________________________________________________________________________________
/*ReaderList*/ else if(!strcmp(cmd,"rl")){
if(!strcmp(actvusr,"\0")) {
printf("\n Please Login Before Using
Commands\n");
}
else{
//call rl ; in rl open spool/username/files.txt
//read it line by line write it and return
void
}
}
//_______________________________________________________________________________________________________________
/*Whoami*/ else if(!strcmp(cmd,"whoami")){
if(!strcmp(actvusr,"\0")){
printf("\nUnidentified Person\n");
}
else{
printf("\n %s \n",actvusr);
}
}
//_______________________________________________________________________________________________________________
/*Logout*/ else if(!strcmp(cmd,"logout")){
if(!strcmp(actvusr,"\0")){
printf("\n You Are Not Seems to be
Logged\n");
}
else{
printf("\n Thank You For Using FS-1a Please
Contact
alper_egitmen@hotmail.com For Bugs \n" );
actvusr[0]='\0';
}
}
//________________________________________________________________________________________________________________
/*SEND*/ else if(!strcmp(cmd,"send")){
if(!strcmp(actvusr,"\0")) {
printf("\n Please Login Before Using
Commands\n");
}
else{
while(comand[i]!=32){
param1[j]=comand[i];
i++;
j++;
}
param1[j]='\0';
i++;
while(comand[i]!=32){
param2[k]=comand[i];
i++;
k++;
}
param2[k]='\0';
printf("\n command : %s\n",cmd );
printf("\n param1 : %s\n",param1);
printf("\n param2 :
%s\n",param2);
}
// call send without any permission check
}
//_________________________________________________________________________________________________________________
/*Receive*/ else if(!strcmp(cmd,"receive")) {
if(!strcmp(actvusr,"\0")) {
printf("\n Please Login Before Using
Commands\n");
}
else{
while(comand[i]!=32){
param1[j]=comand[i];
i++;
j++;
}
param1[j]='\0';
strcpy(param2,actvusr);
printf("\n command : %s\n",cmd );
printf("\n param1 : %s\n",param1);
printf("\n param2 :
%s\n",param2);
//call receive without any permission
chech
}
}
//________________________________________________________________________________________________________________
/* SETPASS*/ else if(!strcmp(cmd,"setp")){
if(!strcmp(actvusr,"\0")) {
printf("\n Please Login Before Using
Commands\n");
}
else{
//get id from uid , using id get information
"setpass" from users.dat
//if ok ; than as for old pass
//if ok ask new pass
//change pass with using id from passwd.dat
}
}
//_______________________________________________________________________________________________________________
// commands ends //
else if(!strcmp(cmd,"\0"));
else
printf("\n\n Unknown Command\n\n");
}
while(strcmp(cmd,"exit"));
return 0;
}
</code>
_______________________________________________
Linux-programlama mailing list
Linux-programlama_at_liste.linux.org.tr
http://liste.linux.org.tr/mailman/listinfo/linux-programlama
Received on Wed 09 Jan 2008 - 22:16:39 EET