<?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=Prove_pratiche_2019</id>
	<title>Prove pratiche 2019 - 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=Prove_pratiche_2019"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2019&amp;action=history"/>
	<updated>2026-05-14T10:11:56Z</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=Prove_pratiche_2019&amp;diff=2968&amp;oldid=prev</id>
		<title>Flecart: /* 2019-02-15 */</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2019&amp;diff=2968&amp;oldid=prev"/>
		<updated>2023-04-26T19:16:21Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;2019-02-15&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:16, 26 April 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l87&quot; &gt;Line 87:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 87:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== Esercizio 2 ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Flecart</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2019&amp;diff=2967&amp;oldid=prev</id>
		<title>Flecart: Created page with &quot; = 2019-02-15 =  == Esercizio 1 ==  === Proposta 1 (Da controllare) ===  ~~~~  &lt;syntaxhighlight lang=&quot;C&quot;&gt; #include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;dirent.h&gt; #includ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2019&amp;diff=2967&amp;oldid=prev"/>
		<updated>2023-04-26T19:15:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; = 2019-02-15 =  == Esercizio 1 ==  === Proposta 1 (Da controllare) ===  ~~~~  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;sys/types.h&amp;gt; #include &amp;lt;dirent.h&amp;gt; #includ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
= 2019-02-15 =&lt;br /&gt;
&lt;br /&gt;
== Esercizio 1 ==&lt;br /&gt;
&lt;br /&gt;
=== Proposta 1 (Da controllare) ===&lt;br /&gt;
&lt;br /&gt;
[[User:Flecart|Flecart]] ([[User talk:Flecart|talk]]) 21:15, 26 April 2023 (CEST)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/inotify.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// as docs said, return value is event + MAX_NAME of the file.&lt;br /&gt;
typedef struct event {&lt;br /&gt;
    struct inotify_event ev;&lt;br /&gt;
    char name[256 + 1];&lt;br /&gt;
} event_t;&lt;br /&gt;
&lt;br /&gt;
char *get_name(char *dir_name, char *file_name) {&lt;br /&gt;
    int dir_len = strlen(dir_name);&lt;br /&gt;
    int file_len = strlen(file_name);&lt;br /&gt;
    char *space = (char *) malloc(dir_len + file_len + 2);&lt;br /&gt;
&lt;br /&gt;
    strcpy(space, dir_name);&lt;br /&gt;
    space[dir_len] = '/';&lt;br /&gt;
    strcat(space, file_name);&lt;br /&gt;
    space[1 + dir_len + file_len] = '\0';&lt;br /&gt;
&lt;br /&gt;
    return space ;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int is_dir(char *dirname) {&lt;br /&gt;
    int n = 0;&lt;br /&gt;
    struct dirent *d;&lt;br /&gt;
    DIR *dir = opendir(dirname);&lt;br /&gt;
    if (dir == NULL) return 0;&lt;br /&gt;
    while ((d = readdir(dir)) != NULL) &lt;br /&gt;
        if (++n &amp;gt; 2)&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
    closedir(dir);&lt;br /&gt;
&lt;br /&gt;
    if (n &amp;lt;= 2) return 1;&lt;br /&gt;
    else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    if (argc != 2) {&lt;br /&gt;
        printf(&amp;quot;USAGE: doanddelete &amp;lt;directory&amp;gt;\n&amp;quot;);&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    if (!is_dir(argv[1])) {&lt;br /&gt;
        printf(&amp;quot;%s is not a directory or not empty, exiting \n&amp;quot;, argv[1]);&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    int init = inotify_init();&lt;br /&gt;
&lt;br /&gt;
    int ret_val = inotify_add_watch(init, argv[1], IN_CREATE | IN_MOVED_TO);&lt;br /&gt;
    if (ret_val == -1) {&lt;br /&gt;
        printf(&amp;quot;inotify_add_watch failed with errno: %d\n&amp;quot;, errno);&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    struct event eventt;&lt;br /&gt;
    int num_bytes_read;&lt;br /&gt;
    while ((num_bytes_read = read(init, &amp;amp;eventt, sizeof(struct event))) &amp;gt; 0) {&lt;br /&gt;
        char * name = get_name(argv[1], eventt.name);&lt;br /&gt;
        printf(&amp;quot;concatenated name is %s\n&amp;quot;, name);&lt;br /&gt;
&lt;br /&gt;
        if (fork()) {&lt;br /&gt;
            execl(name, name, NULL);&lt;br /&gt;
        }&lt;br /&gt;
        unlink(name); &lt;br /&gt;
        free(name);&lt;br /&gt;
    }&lt;br /&gt;
    // 18:59&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Flecart</name></author>
	</entry>
</feed>