»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

c¾ð¾î, ½Ã½ºÅÛÇÁ·Î±×·¡¹Ö Áú¹®µå·Á¿ä...¸®´ª½º2

#include
#include
#include
#include
#include

#define MAX_PATH 5

main(int argc, char **argv)
{
        char line[256], *pathPtr[MAX_PATH];

        char *tempLine[MAX_PATH];
        char tempLine2[30];
        
        // read ".myshell" file, and adjust pathPtr.;
        int fd; // ".myshell" file descriptor
        char buf[1];
        char tempPtr[20];
        
        
        
        int i;        
        int rd_cnt;
        int j=0;
        int k=0;
                
        int path=0;

        if((fd=open(".myshell",O_RDONLY))<0)<br />         {
                perror(".myshell error\n");
                exit(1);
        }
        
        lseek(fd,5,SEEK_SET);
        
        while(read(fd,buf,1)>0)
        {        
                if(buf[0]==':')
                {
                        pathPtr[path]=strdup(tempPtr);
                        path++;
                        memset(tempPtr,0,sizeof(tempPtr));
                        //strcpy(tempPtr,"");
                }                
                
                if(buf[0]!=':')
                {
                        //printf("%c",buf[0]);
                        strncat(tempPtr, buf,1);
                }
                        
        }
                

        
        
        printf("file read end\n");
        /*
        printf("%s\n",pathPtr[0]);
        printf("%s\n",pathPtr[1]);
        */

        
        
        while(1)
        {
                for(k=0; k                 {
                        tempLine[k]=strdup(pathPtr[k]);
                }
                
                /*
                for(k=0; k                 {
                        printf("%s\n",tempLine[k]);
                }
                */

                
                printf("COMMAND : ");
                fgets(line, 255, stdin);
                //extract command in "Line";
                

                for(k=0; k                 {
                        strcpy(tempLine2, tempLine[k]);
                        strcat(tempLine2,"/");
                        strcat(tempLine2, line);
                        
                        tempLine[k] = strdup(tempLine2);
                        //printf("%s\n",tempLine[k]);
                }
                //test//
                /*
                if(access("/bin/rm", F_OK)!=0)
                {
                        printf("X\n");
                }
                else
                {
                        printf("O\n");
                }
                exit(1);
                */




                for(k=0; k                 {
                        if(access(tempLine[k], F_OK)!= 0)
                        {
                                
                                printf("%s [X] \n",tempLine[k]);
                        }
                        else
                        {
                                printf("%s [O]\n",tempLine[k]);
                        }
                }
                exit(0);

///////////////////////////////////////////////////////////////////
À̺κÐÀÔ´Ï´Ù. test·Î ÁÖ¼®ÃijõÀº °÷¿¡
access·Î Á÷Á¢ "/bin/rm" ÀÌ·¸°Ô °Ë»ç¸¦ Çغ¸¸é...
O°¡ Ãâ·ÂÀÌ µË´Ï´Ù.. ÆÄÀÏÀÌ Á¸ÀçÇÑ´Ù´Â ¶æÀÌÁö¿ä...

ÇÏÁö¸¸ Á¦°¡ .myshell¿¡ ÀÖ´Â ³»¿ëÀ» ¹Þ¾Æ¼­ Ãâ·ÂÀ» ÇÏ°Ô µÇ¸é
%s·Î Âï¾îº¸¸é /bin/rm ÀÌ·¸°Ô ³ª¿À´Âµ¥
Á¤ÀÛ.. access°¡ Á¤»óµ¿ÀÛÀ» ÇÏÁö ¾Ê½À´Ï´Ù...

¾îµð¼­ À߸øµÈ°ÇÁö... ³Ê¹« ÇظŰíÀÖ½À´Ï´Ù..
Á¶¾ðÁ» ¹ÞÀ» ¼ö ÀÖÀ»±î¿ä?..

Ȥ½Ã¸ô¶ó¼­ ÆÄÀÏ÷ºÎ Çص帳´Ï´Ù.

.myshell ÀÇ ³»¿ëÀº PATH=/bin:/usr/bin: ÀÔ´Ï´Ù...
lseek·Î PATH= ºÎºÐ Åë°úÇÏ°í /binºÎÅÍ ¹Þ¾Æ¿É´Ï´Ù..



//////////////////////////////////////////////////////


                // find command in pathPtr path;
                if(1)
                {
                        if(fork()==0)
                        {
                                //execute command with option;
                        }
                        //wait until child terminates;
                        else
                        {
                                printf("Command not found\n");
                        }
                }
        }

}

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°
÷ºÎÆÄÀÏ

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 [* ºñȸ¿ø *]

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¸¶Äí¸®Äí¸®
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û ¸ñ·Ïº¸±â