Tag Archive for lines

C – create Process Daemon

#include <stdio.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
/*
* Funzione che mi crea un demone
*/

int pid;

// create - fork 1
if(fork()) return 0;

// it separates the son from the father
chdir("/");
setsid();
umask(0);

// create - fork 2
pid = fork();

if(pid)
{
printf("Daemon: %d
", pid);
return 0;
}

/****** Codice da eseguire ********/
FILE *f;

f=fopen("/tmp/coa.log", "w");

while(1)
{
fprintf(f, "ciao
");
fflush(f);
sleep(2);
}
/**********************************/
}

source

C – Example Buffer OverFlow

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
char *buffer1 = (char *)calloc(5, sizeof(char));
char *buffer2 = (char *)calloc(15, sizeof(char));
char *tmp;

strcpy(buffer2, "ls -a --color");
strcpy(buffer1, argv[1]);

// Indirizzi di memoria...
printf("%p <-- buffer1
", buffer1);
printf("%p <-- buffer2
", buffer2);
printf("

");

// Stampa indirizzi...
printf("Start code....
");
tmp=buffer1;
while(tmp<buffer2+15)
{
printf("%p: %c (0x%x)
", tmp, *tmp, *(unsigned int *)tmp);
tmp++;
}

printf("
");
system(buffer2);
return 0;
}

source

Rails breakup long lines

def break_up_long_line(str, max)
counter = 0
new_text = ''
for i in 0...str.length
if str[i,1] =~ /
/
counter = 0
else
counter = counter + 1
end
new_text << str[i,1]
if counter >= max && str[i,1] =~ /s/
new_text << "
"
counter = 0
end
end
new_text
end

source

php breakup long lines

function breakUpLongLines( $text, $maxLength=80 )
{
$counter = 0;
$newText = '';
$array = array();

$textLength = strlen( $text );

for( $i = 0; $i <= $textLength; $i++ )
{
$array[] = substr( $text, $i, 1 );
}

$textLength = count( $array );

for( $x = 0; $x < $textLength; $x++ )
{
if( preg_match( "/[[:space:]]/", $array[ $x ] ) )
{
$counter = 0;
}
else
{
$counter++;
}

$newText .= $array[ $x ];

if( $counter >= $maxLength )
{
$newText .= ' ';

$counter = 0;
}
}

return $newText;
}

source