Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smooth differences between tests before merge
[simgrid.git] / examples / msg / io / file_unlink.c
1 /* Copyright (c) 2008-2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /** @addtogroup MSG_examples
8  * 
9  * - <b>io/file_unlink.c</b> TBA
10  */
11
12 #define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
13
14 #include "simgrid/msg.h"
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(io_file, "Messages specific for this io example");
17
18 static int host(int argc, char *argv[])
19 {
20   // First open
21   XBT_INFO("\tOpen file '%s'",FILENAME1);
22   msg_file_t file = MSG_file_open(FILENAME1, NULL);
23
24   // Unlink the file
25   XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file));
26   MSG_file_unlink(file);
27
28   // Re Open the file wich is in fact created
29   XBT_INFO("\tOpen file '%s'",FILENAME1);
30   file = MSG_file_open(FILENAME1, NULL);
31
32   // Write into the new file
33   sg_size_t write = MSG_file_write(file,100000);  // Write for 100Ko
34   XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
35
36   // Write into the new file
37   write = MSG_file_write(file,100000);  // Write for 100Ko
38   XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
39
40   // Close the file
41   XBT_INFO("\tClose file '%s'",MSG_file_get_name(file));
42   MSG_file_close(file);
43
44   return 0;
45 }
46
47 int main(int argc, char **argv)
48 {
49   MSG_init(&argc, argv);
50   MSG_create_environment(argv[1]);
51   xbt_dynar_t hosts =  MSG_hosts_as_dynar();
52   MSG_function_register("host", host);
53   unsigned long nb_hosts = xbt_dynar_length(hosts);
54   XBT_INFO("Number of host '%lu'",nb_hosts);
55   char* name_host = xbt_strdup("0");
56   MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,0,msg_host_t) );
57   free(name_host);
58
59   xbt_dynar_free(&hosts);
60
61   int res = MSG_main();
62   XBT_INFO("Simulation time %g", MSG_get_clock());
63   return res != MSG_OK;
64 }