peri mkstemp

Christos Ricudis ricudis at paiko.gr
Sun Feb 7 19:42:11 EET 1999


Hello Linux-greek-users!

  On 07 Feb 99, Linux-greek-users wrote to All with subject "peri mkstemp":


 L> re gmt giati to parakatw den douleuei?
 L> Egrapsa 5-6 grammes kwdika gia na ftiaxnei ena temporary file :

Profanws o didaskwn ka8hghths sto ma8hma ths C sto Salford einai o Niklaus
Wirth. 

 L> #include <unistd.h>
 L> #include <stdio.h>
 L> #include <stdlib.h>
 L> #include <sys/stat.h>

 L> main(){

void main(void) {

 L> int fd;
 L> char *k;

 L>         k= (char *) malloc(sizeof(k));

sizeof(k)==4. Kaneis allocate 4 bytes gia ena string twn 26 bytes.

 L>         k="/ergasia/temp/koukouXXXXXX";

8elw kai gw ligo apo ayto poy kapnizeis, prepei na einai poly kalo...

H balto se array kai kane initialization :

char k[10]="/ergasia/temp/koukouXXXXXX";

H xrhsimopoihse thn strncpy

k=strcpy(k,"/ergasia/temp/koukouXXXXXX");

(Diaforoi security wizards me meso oro hlikias ta 14 8a sou poyn oti h strcpy
einai epikindynh giati den kanei bounds checking. Ayto ontws isxyei, alla
merikes fores den exei nohma na kaneis bounds checking - opws 8A SYNEBAINE sthn
periptwsh mas AN ekanes allocate arketo xwro gia na krathsei to string).

 L>         umask(022);

This one does not do what you intent to do. Re-read the man page of mkstemp,
then use chmod(2).

 L>         fd=mkstemp(k);
 L>         write(fd,"patates",sizeof("patates"));

Mhpws ennoouses write(fd,"patates",strlen("patates"))?

Sthn sygkekrimenh periptwsh to sizeof("something constant") aplws TYXAINEI na
einai iso me to strlen("something constant"). Molis allakseis tis "patates" me
ena char * h ena char [], pes antio.

 L>         close(fd);
 L>         printf("%i",fd);
 L>         free(k);
 L> }



--
Christos Ricudis
Prof:    So the American government went to IBM to come up with a data
         encryption standard and they came up with ...
Student: EBCDIC!
--
====================================================================
Gia boithia (h na diagrafhte) e-mail sto majordomo at hellug.gr
Ta archives tis listas einai sto http://lists.hellug.gr
prin steilete kapoia erothsh psakte mipos exei hdh apanththei.
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users
====================================================================



More information about the Linux-greek-users mailing list