<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=ProvaPratica_2009.09.23</id>
	<title>ProvaPratica 2009.09.23 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=ProvaPratica_2009.09.23"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.09.23&amp;action=history"/>
	<updated>2026-05-03T07:33:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.09.23&amp;diff=645&amp;oldid=prev</id>
		<title>Mirk M: Created page with &quot;&lt;h1&gt;http://www.cs.unibo.it/~renzo/so/pratiche/2009.09.23.pdf&lt;/h1&gt;  == Esercizio 1 ==  &lt;syntaxhighlight lang=&quot;C&quot;&gt; #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;unistd.h&gt; #in...&quot;</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2009.09.23&amp;diff=645&amp;oldid=prev"/>
		<updated>2014-04-30T13:59:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/pratiche/2009.09.23.pdf&amp;lt;/h1&amp;gt;  == Esercizio 1 ==  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;unistd.h&amp;gt; #in...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/pratiche/2009.09.23.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BUFSIZE 4096&lt;br /&gt;
&lt;br /&gt;
void buf_invert(char *b_input, char *b_output)&lt;br /&gt;
{&lt;br /&gt;
	int i;&lt;br /&gt;
&lt;br /&gt;
	for(i=0; i&amp;lt;BUFSIZE; i++)&lt;br /&gt;
	{&lt;br /&gt;
		if(b_input[i] == EOF)&lt;br /&gt;
			break;&lt;br /&gt;
		b_output[i] = b_input[BUFSIZE-i];&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
off_t file_dim(char *path)&lt;br /&gt;
{&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	int ris;&lt;br /&gt;
&lt;br /&gt;
	ris = stat (path, &amp;amp;buf);&lt;br /&gt;
	if(ris == -1)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Stat, error %d: %s\n&amp;quot;, errno, strerror(errno));&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return buf.st_size;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int invert(int input, int output, off_t file_size)&lt;br /&gt;
{&lt;br /&gt;
	char b_input[BUFSIZE], b_output[BUFSIZE];&lt;br /&gt;
	int rris, wris;&lt;br /&gt;
	off_t i=0;&lt;br /&gt;
&lt;br /&gt;
	while(i &amp;lt; file_size)&lt;br /&gt;
	{&lt;br /&gt;
		rris = pread(input, b_input, BUFSIZE, i);&lt;br /&gt;
		if(rris == -1)&lt;br /&gt;
		{&lt;br /&gt;
			printf(&amp;quot;Pread error %d: %s\n&amp;quot;, errno, strerror(errno));&lt;br /&gt;
			return -1;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		i += rris;&lt;br /&gt;
&lt;br /&gt;
		wris = pwrite(output, b_output, BUFSIZE, file_size-i);&lt;br /&gt;
		if(wris == -1)&lt;br /&gt;
		{&lt;br /&gt;
			printf(&amp;quot;Pwrite error %d: %s\n&amp;quot;, errno, strerror(errno));&lt;br /&gt;
			return -1;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		if(rris != wris)&lt;br /&gt;
		{&lt;br /&gt;
			printf(&amp;quot;Invert error\n&amp;quot;);&lt;br /&gt;
			return -1;&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
	int input, output, ris;&lt;br /&gt;
	off_t file_size;&lt;br /&gt;
&lt;br /&gt;
	if(argc &amp;gt; 3)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Too many arguments\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	input = open(argv[1], O_RDONLY);&lt;br /&gt;
	if(input == -1)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Open error %d: %s\n&amp;quot;, errno, strerror(errno));&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	file_size = file_dim(argv[1]);&lt;br /&gt;
	if(file_size == -1)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;File_dim error\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	printf(&amp;quot;File size %d\n&amp;quot;, file_size);&lt;br /&gt;
&lt;br /&gt;
	output = open(argv[2], O_CREAT | O_RDWR /*| O_APPEND*/);&lt;br /&gt;
	if(output == -1)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;File creation (open) error %d: %s\n&amp;quot;, errno, strerror(errno));&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	ris = invert(input, output, file_size);&lt;br /&gt;
	if(ris == -1)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Invert error\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mirko_M&lt;/div&gt;</summary>
		<author><name>Mirk M</name></author>
	</entry>
</feed>