コード例 #1
0
ファイル: test-fs-event.c プロジェクト: aleks-f/libuv
static void timer_cb_file(uv_timer_t* handle, int status) {
  ++timer_cb_called;

  if (timer_cb_called == 1) {
    touch_file(handle->loop, "watch_dir/file1");
  } else {
    touch_file(handle->loop, "watch_dir/file2");
    uv_close((uv_handle_t*)handle, close_cb);
  }
}
コード例 #2
0
ファイル: tests.c プロジェクト: dbhoekman/CS360
//This tests touch and creat
//First test makes sure the mtime changes on a file that exists.
//Returns 0 if the time isnt greater than what it was before.
//Second test touches a file that doesnt exits, and therefore makes one.
//Checks the inode of the new file, and if isn't what is expected, returns zero.
//This second test checks both if touch and creat are working.
int touchTest()
{
  MINODE *test_mip = running->cwd;
  INODE *ip = NULL;
  int ino = 0;
  int old = 0;
  int expected1 = 28;

  strcpy(pathname, "");
  cd(pathname);
  test_mip = running->cwd;
  printf("\n\n-------- TESTING TOUCH FUNCTION --------\n\n");

  strcpy(pathname, "tiny");
  ino = getino(test_mip, pathname);
  test_mip = iget(dev, ino);
  ip = &test_mip->INODE;

  old = ip->i_mtime;
  printf("tiny's current mtime = %d\n", ip->i_mtime);
  printf("Testing >touch tiny\n");
  strcpy(pathname, "tiny");
  touch_file(pathname);
  printf("tiny's new mtime = %d\n", ip->i_mtime);

  if(ip->i_mtime > old)
    printf("TEST PASSED!\n\n");
  else
  {
    printf("TEST FAILED!\n\n");
    return 0;
  }


  test_mip = running->cwd;
  printf("Testing >touch newfile\n");
  strcpy(pathname, "newfile");
  touch_file(pathname);

  strcpy(pathname, "newfile");
  ino = getino(test_mip, pathname);
  printf("Expected ino of newfile = %d\n", expected1);
  printf("Actual ino of newfile = %d\n", ino);
  if (ino != expected1)
  {
    printf("TEST FAILED!\n\n");
    return 0;
  }
  printf("TEST PASSED!\n\n");

  printf("\nALL TOUCH TESTS PASSED!\n\n\n");
	return 1;
}
コード例 #3
0
/**
 * e_db3_utils_upgrade_format:
 * @filename: path to a Berkeley DB file
 *
 * Upgrades the file format of a Berkeley DB file from a previous version.
 *
 * Returns: 0 if successful, -1 on failure
 **/
gint
e_db3_utils_upgrade_format (const gchar *filename)
{
	gchar *copy_filename;
	gchar *check_filename;
	DB *db;
	gint ret_val;

	ret_val = db_create (&db, NULL, 0);
	if (ret_val != 0)
		return ret_val;

	copy_filename = get_copy_filename (filename);
	check_filename = get_check_filename (filename);

	ret_val = cp_file (filename, copy_filename);

	if (ret_val == 0)
		ret_val = touch_file (check_filename);
	if (ret_val == 0)
		ret_val = db->upgrade (db, filename, 0);
	if (ret_val == 0)
		ret_val = g_unlink (check_filename);

	if (ret_val == 0)
		ret_val = g_unlink (copy_filename);

	db->close (db, 0);

	g_free (check_filename);
	g_free (copy_filename);
	return ret_val;
}
コード例 #4
0
ファイル: dgrep.c プロジェクト: jarmoruuth/tools
/**********************************************************************
 *
 *	check_flags
 */
static status_t check_flags(char* beg, char* end, char* bufend)
{
	was_match = TRUE;
#ifdef TOUCH
	if (touch)
		touch_file(path);
#endif
	if (names) {
		if (!silent)
			printf("%s\n", path);
		return STOP;
	}
	if (count) {
		matchcount++;
		return OK;
	}
	if (silent)
		return OK;
	if (!first_match && (leading_context || trailing_context))
		printf("----------\n");
	first_match = FALSE;
	if (leading_context)
		print_leading_context(buffer, beg-1);
	print_line(beg, end, linecount);
	if (trailing_context)
		waiting_lines = print_trailing_context(end+NEOL(end), bufend);
	if (number)
		linecount++;
	return OK;
}
コード例 #5
0
ファイル: account.c プロジェクト: bcho-archive/aqulia
inline static void
personal_read(char *fname, struct account *account)
{
    struct csv_header *header;
    struct csv_row *row;
    FILE *stream;

    touch_file(fname);
    if ((stream = fopen(fname, "r")) == NULL)
        ERROR("read personal %s", fname);

    header = csv_read_header(stream);
    if (header == NULL)
        header = csv_read_header_from_string(DEFAULT_HEADER);
    prepare_header(header);

    row = csv_read_row(stream, header);
    if (row == NULL)
        return;

    account->cardno = csv_find_row(row, "cardno")->value.i;
    account->expire = strdup(csv_find_row(row, "expire")->value.s);
    account->balance = csv_find_row(row, "balance")->value.d;
    account->state = csv_find_row(row, "state")->value.i;
    account->faculty = strdup(csv_find_row(row, "faculty")->value.s);

    csv_destory_row(row);
    csv_destory_header(header);
    fclose(stream);
}
コード例 #6
0
ファイル: chown.c プロジェクト: jaredm94/File-System
// Modify INODE.i_mode's permission bits
int chown_file()
{
    int newOwner = atoi(pathM);
    char *pathname = parameterM;
    
    int dev, ino;
    MINODE *mp;

    // Get inode
    if(pathname[0] == '/') dev = root->dev;
    else dev = running->cwd->dev;
    ino = getino(dev, pathname);
    if (ino == EXIT_FAILURE)
    {
        printf("CHMOD: File does not exist\n");
        return EXIT_FAILURE;
    }
    mp = iget(dev, ino);

    // Update owner
    mp->INODE.i_uid = newOwner;

    // Write file back
    mp->dirty = 1;
    iput(mp);

    // Update file access time
    touch_file(pathname);

    return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: mmap-mprotect-test.c プロジェクト: Safe3/tpe-lkm
int do_mmap(const char *filename) {

	int ret = 0;
	int fd;
	int *map;

	touch_file(filename);

	fd = open(filename, 0, (mode_t)0755);

	if (fd == -1) {
		perror("Error opening file for writing");
		exit(EXIT_FAILURE);
	}

	map = mmap(0, 10, PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0);

	if (map != MAP_FAILED)
		ret = 1;

	perror("exec via mmap");
	
	close(fd);

	unlink(filename);

	return ret;
}
コード例 #8
0
ファイル: test-fs-poll.c プロジェクト: 1048046563/node
static void poll_cb(uv_fs_poll_t* handle,
                    int status,
                    const uv_stat_t* prev,
                    const uv_stat_t* curr) {
  uv_stat_t zero_statbuf;

  memset(&zero_statbuf, 0, sizeof(zero_statbuf));

  ASSERT(handle == &poll_handle);
  ASSERT(1 == uv_is_active((uv_handle_t*) handle));
  ASSERT(prev != NULL);
  ASSERT(curr != NULL);

  switch (poll_cb_called++) {
  case 0:
    ASSERT(status == UV_ENOENT);
    ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    touch_file(FIXTURE);
    break;

  case 1:
    ASSERT(status == 0);
    ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 20, 0));
    break;

  case 2:
    ASSERT(status == 0);
    ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 200, 0));
    break;

  case 3:
    ASSERT(status == 0);
    ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    remove(FIXTURE);
    break;

  case 4:
    ASSERT(status == UV_ENOENT);
    ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    uv_close((uv_handle_t*)handle, close_cb);
    break;

  default:
    ASSERT(0);
  }
}
コード例 #9
0
ファイル: test-conf-files.c プロジェクト: Mathnerd314/systemd
static void setup_test_dir(char *tmp_dir, const char *files, ...) {
        va_list ap;

        assert_se(mkdtemp(tmp_dir) != NULL);

        va_start(ap, files);
        while (files != NULL) {
                _cleanup_free_ char *path = strappend(tmp_dir, files);
                assert_se(touch_file(path, true, (usec_t) -1, (uid_t) -1, (gid_t) -1, 0) == 0);
                files = va_arg(ap, const char *);
        }
        va_end(ap);
}
コード例 #10
0
ファイル: test-fs-event.c プロジェクト: AlexanderPankiv/node
static void timer_cb_exact(uv_timer_t* handle) {
  int r;

  if (timer_cb_exact_called == 0) {
    touch_file("watch_dir/file.js");
  } else {
    uv_close((uv_handle_t*)handle, NULL);
    r = uv_fs_event_stop(&fs_event);
    ASSERT(r == 0);
    uv_close((uv_handle_t*) &fs_event, NULL);
  }

  ++timer_cb_exact_called;
}
コード例 #11
0
ファイル: timesyncd.c プロジェクト: crawford/systemd
static int load_clock_timestamp(uid_t uid, gid_t gid) {
        _cleanup_close_ int fd = -1;
        usec_t min = TIME_EPOCH * USEC_PER_SEC;
        usec_t ct;
        int r;

        /* Let's try to make sure that the clock is always
         * monotonically increasing, by saving the clock whenever we
         * have a new NTP time, or when we shut down, and restoring it
         * when we start again. This is particularly helpful on
         * systems lacking a battery backed RTC. We also will adjust
         * the time to at least the build time of systemd. */

        fd = open("/var/lib/systemd/clock", O_RDWR|O_CLOEXEC, 0644);
        if (fd >= 0) {
                struct stat st;
                usec_t stamp;

                /* check if the recorded time is later than the compiled-in one */
                r = fstat(fd, &st);
                if (r >= 0) {
                        stamp = timespec_load(&st.st_mtim);
                        if (stamp > min)
                                min = stamp;
                }

                /* Try to fix the access mode, so that we can still
                   touch the file after dropping priviliges */
                fchmod(fd, 0644);
                fchown(fd, uid, gid);

        } else
                /* create stamp file with the compiled-in date */
                touch_file("/var/lib/systemd/clock", true, min, uid, gid, 0644);

        ct = now(CLOCK_REALTIME);
        if (ct < min) {
                struct timespec ts;
                char date[FORMAT_TIMESTAMP_MAX];

                log_info("System clock time unset or jumped backwards, restoring from recorded timestamp: %s",
                         format_timestamp(date, sizeof(date), min));

                if (clock_settime(CLOCK_REALTIME, timespec_store(&ts, min)) < 0)
                        log_error_errno(errno, "Failed to restore system clock: %m");
        }

        return 0;
}
コード例 #12
0
int main(int argc, char** argv)
{
    if (argc != 2)
    {
        show_usage();
        return -1;
    }
    const size_t buckets = boost::lexical_cast<size_t>(argv[1]);

    const size_t total_txs = read_total("values.seqdb");
    // Copied from prepare.cpp
    const size_t max_tx_size = 400;

    BITCOIN_ASSERT(buckets > 0);
    std::cout << "Buckets: " << buckets << std::endl;

    touch_file("htdb_slabs");
    mmfile file("htdb_slabs");
    BITCOIN_ASSERT(file.data());
    file.resize(4 + 8 * buckets + 8 + total_txs * max_tx_size * 2);

    htdb_slab_header header(file, 0);
    header.initialize_new(buckets);
    header.start();

    slab_allocator alloc(file, 4 + 8 * buckets);
    alloc.initialize_new();
    alloc.start();

    htdb_slab<hash_digest> ht(header, alloc);

    size_t number_wrote = 0;
    auto read = [&ht, &number_wrote](const data_chunk& value)
    {
        const hash_digest key = bitcoin_hash(value);
        auto write = [&value](uint8_t* data)
        {
            std::copy(value.begin(), value.end(), data);
        };
        ht.store(key, value.size(), write);
        ++number_wrote;
    };
    iterate_values("values.seqdb", read);

    alloc.sync();
    std::cout << "Wrote " << number_wrote << " values. Done." << std::endl;
    return 0;
}
コード例 #13
0
ファイル: file.c プロジェクト: nielssp/ctodo
TODOLIST *load_todolist(char *filename) {
  TODOLIST *list = NULL;
  STREAM *file = stream_file(filename, "r");
  if (!file) {
    if (touch_file(filename)) {
      return load_todolist(filename);
    }
    else {
      error("%s", strerror(errno));
      return NULL;
    }
  }
  list = read_todolist(file);
  stream_close(file);
  return list;
}
コード例 #14
0
ファイル: AdvancedPage.cpp プロジェクト: IRET0x00/vidalia
/** Open a QFileDialog to browse for Tor config file. */
void
AdvancedPage::browseTorConfig()
{
  /* Prompt the user to select a file or create a new one */
  QString filename = QFileDialog::getOpenFileName(this, 
                       tr("Select Tor Configuration File"),
                       QFileInfo(ui.lineTorConfig->text()).filePath(),
                       tr("Tor Configuration File (torrc);;All Files (*)"));

  /* Make sure a filename was selected */
  if (filename.isEmpty()) {
    return;
  }

  /* Check if the file exists */
  QFile torrcFile(filename);
  if (!QFileInfo(filename).exists()) {
    /* The given file does not exist. Should we create it? */
    int response = VMessageBox::question(this,
                     tr("File Not Found"),
                     tr("%1 does not exist. Would you like to create it?")
                                                            .arg(filename),
                     VMessageBox::Yes, VMessageBox::No);
    
    if (response == VMessageBox::No) {
      /* Don't create it. Just bail. */
      return;
    }
    /* Attempt to create the specified file */
    QString errmsg;
    if (!touch_file(filename, false, &errmsg)) {
      VMessageBox::warning(this,
        tr("Failed to Create File"),
        tr("Unable to create %1 [%2]").arg(filename)
                                      .arg(errmsg),
        VMessageBox::Ok);
      return;
    }
  }
  ui.lineTorConfig->setText(filename);
}
コード例 #15
0
ファイル: mmap-mprotect-test.c プロジェクト: Safe3/tpe-lkm
int do_mprotect(const char *filename) {

	int ret = 0;
	int fd;
	int *map;

	touch_file(filename);

	fd = open(filename, 0, (mode_t)0755);

	if (fd == -1) {
		perror("Error opening file for writing");
		exit(EXIT_FAILURE);
	}

	map = mmap(0, 10, PROT_READ, MAP_PRIVATE, fd, 0);

	if (map == MAP_FAILED) {
		printf("mmap write failed in mprotect test\n");
		exit(EXIT_FAILURE);
	}

	ret = mprotect(map, sizeof(unsigned long), PROT_EXEC);

	if (ret == -1)
		ret = 0;
	else
		ret = 1;

	perror("exec via mprotect");
	
	close(fd);

	unlink(filename);

	return ret;
}
コード例 #16
0
struct ntt *ntt_create(long size) {
    struct ntt *ntt;
    struct shmht * htbl;
    
    ntt = (struct ntt *) malloc(sizeof(struct ntt));
    if( !ntt ) {
      return NULL;
    }
    
    // Touch file >.>
    touch_file(MEV_FILE);
    
    ntt->size = size;
    ntt->htbl = create_shmht(MEV_FILE, size, 
                              sizeof(struct ntt_node), dbj2_hash, str_compar);
    
    if( !ntt->htbl ) {
      LOG(LOG_ALERT, "Failed to create hash table");
      free(ntt);
      return NULL;
    }
    
    return ntt;
}
コード例 #17
0
ファイル: richole.c プロジェクト: thomcom/wine
static void test_ITextDocument_Open(void)
{
  IRichEditOle *reOle = NULL;
  ITextDocument *txtDoc = NULL;
  ITextSelection *txtSel = NULL;
  HRESULT hres;
  HWND w;
  HANDLE hFile;
  VARIANT testfile;
  WCHAR filename[] = {'t', 'e', 's', 't','.','t','x','t', 0};

  static const int tomConstantsSingle[] =
    {
      tomReadOnly, tomShareDenyRead, tomShareDenyWrite,
      tomCreateAlways, tomOpenExisting, tomOpenAlways,
      tomTruncateExisting, tomRTF, tomText
    };

  static const int tomConstantsMulti[] =
    {
      tomReadOnly|tomShareDenyRead|tomPasteFile, tomReadOnly|tomPasteFile,
      tomReadOnly|tomShareDenyWrite|tomPasteFile,
      tomReadOnly|tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyWrite|tomPasteFile,
      tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyRead|tomPasteFile,
      tomShareDenyRead|tomShareDenyWrite, tomReadOnly|tomShareDenyRead|tomShareDenyWrite,
      tomReadOnly|tomShareDenyWrite, tomReadOnly|tomShareDenyRead
    };

  int tomNumSingle =  sizeof(tomConstantsSingle)/sizeof(tomConstantsSingle[0]);
  int tomNumMulti = sizeof(tomConstantsMulti)/sizeof(tomConstantsMulti[0]);
  int i;
  VariantInit(&testfile);
  V_VT(&testfile) = VT_BSTR;
  V_BSTR(&testfile) = SysAllocString(filename);

  for(i=0; i < tomNumSingle; i++)
    {
      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_ACP);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
         tomConstantsSingle[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);

      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_UTF8);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
         tomConstantsSingle[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);
    }

  for(i=0; i < tomNumMulti; i++)
    {
      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_ACP);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
         tomConstantsMulti[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);

      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_UTF8);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
         tomConstantsMulti[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);
    }

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_ACP);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_UTF8);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_ACP);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_UTF8);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  touch_file(filename);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_ACP\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  touch_file(filename);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_ACP);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_ACP\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_UTF8);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);
  ITextDocument_Open(txtDoc, &testfile, tomText, CP_ACP);
  todo_wine ok(is_existing_file(filename) == TRUE, "a file should be created default\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  /* test of share mode */
  touch_file(filename);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  ITextDocument_Open(txtDoc, &testfile, tomShareDenyRead, CP_ACP);
  SetLastError(0xdeadbeef);
  hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);
  todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
  CloseHandle(hFile);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  touch_file(filename);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite, CP_ACP);
  SetLastError(0xdeadbeef);
  hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);
  todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
  CloseHandle(hFile);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  touch_file(filename);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  SetLastError(0xdeadbeef);
  ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite|tomShareDenyRead, CP_ACP);
  hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);
  todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
  CloseHandle(hFile);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);
}
コード例 #18
0
static void timer_cb_touch(uv_timer_t* timer, int status) {
    ASSERT(status == 0);
    uv_close((uv_handle_t*)timer, NULL);
    touch_file(timer->loop, "watch_file");
    timer_cb_touch_called++;
}
コード例 #19
0
ファイル: remake.c プロジェクト: mturk/gnumake
void
notice_finished_file (struct file *file)
{
  struct dep *d;
  int ran = file->command_state == cs_running;
  int touched = 0;

  file->command_state = cs_finished;
  file->updated = 1;

  if (touch_flag
      /* The update status will be:
		-1	if this target was not remade;
		0	if 0 or more commands (+ or ${MAKE}) were run and won;
		1	if some commands were run and lost.
	 We touch the target if it has commands which either were not run
	 or won when they ran (i.e. status is 0).  */
      && file->update_status == 0)
    {
      if (file->cmds != 0 && file->cmds->any_recurse)
	{
	  /* If all the command lines were recursive,
	     we don't want to do the touching.  */
	  unsigned int i;
	  for (i = 0; i < file->cmds->ncommand_lines; ++i)
	    if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
	      goto have_nonrecursing;
	}
      else
	{
	have_nonrecursing:
	  if (file->phony)
	    file->update_status = 0;
          /* According to POSIX, -t doesn't affect targets with no cmds.  */
	  else if (file->cmds != 0)
            {
              /* Should set file's modification date and do nothing else.  */
              file->update_status = touch_file (file);

              /* Pretend we ran a real touch command, to suppress the
                 "'foo' is up to date" message.  */
              commands_started++;

              /* Request for the timestamp to be updated (and distributed
                 to the double-colon entries). Simply setting ran=1 would
                 almost have done the trick, but messes up with the also_make
                 updating logic below.  */
              touched = 1;
            }
	}
    }

  if (file->mtime_before_update == UNKNOWN_MTIME)
    file->mtime_before_update = file->last_mtime;

  if ((ran && !file->phony) || touched)
    {
      int i = 0;

      /* If -n, -t, or -q and all the commands are recursive, we ran them so
         really check the target's mtime again.  Otherwise, assume the target
         would have been updated. */

      if ((question_flag || just_print_flag || touch_flag) && file->cmds)
        {
          for (i = file->cmds->ncommand_lines; i > 0; --i)
            if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))
              break;
        }

      /* If there were no commands at all, it's always new. */

      else if (file->is_target && file->cmds == 0)
	i = 1;

      file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
    }

  if (file->double_colon)
    {
      /* If this is a double colon rule and it is the last one to be
         updated, propagate the change of modification time to all the
         double-colon entries for this file.

         We do it on the last update because it is important to handle
         individual entries as separate rules with separate timestamps
         while they are treated as targets and then as one rule with the
         unified timestamp when they are considered as a prerequisite
         of some target.  */

      struct file *f;
      FILE_TIMESTAMP max_mtime = file->last_mtime;

      /* Check that all rules were updated and at the same time find
         the max timestamp.  We assume UNKNOWN_MTIME is newer then
         any other value.  */
      for (f = file->double_colon; f != 0 && f->updated; f = f->prev)
        if (max_mtime != UNKNOWN_MTIME
            && (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime))
          max_mtime = f->last_mtime;

      if (f == 0)
        for (f = file->double_colon; f != 0; f = f->prev)
          f->last_mtime = max_mtime;
    }

  if (ran && file->update_status != -1)
    /* We actually tried to update FILE, which has
       updated its also_make's as well (if it worked).
       If it didn't work, it wouldn't work again for them.
       So mark them as updated with the same status.  */
    for (d = file->also_make; d != 0; d = d->next)
      {
	d->file->command_state = cs_finished;
	d->file->updated = 1;
	d->file->update_status = file->update_status;

	if (ran && !d->file->phony)
	  /* Fetch the new modification time.
	     We do this instead of just invalidating the cached time
	     so that a vpath_search can happen.  Otherwise, it would
	     never be done because the target is already updated.  */
	  f_mtime (d->file, 0);
      }
  else if (file->update_status == -1)
    /* Nothing was done for FILE, but it needed nothing done.
       So mark it now as "succeeded".  */
    file->update_status = 0;
}
コード例 #20
0
static void timer_cb_touch(uv_timer_t* timer) {
  uv_close((uv_handle_t*)timer, NULL);
  touch_file(timer->loop, "watch_file");
  timer_cb_touch_called++;
}
コード例 #21
0
ファイル: test-fs-poll.c プロジェクト: 1048046563/node
static void timer_cb(uv_timer_t* handle) {
  touch_file(FIXTURE);
  timer_cb_called++;
}
コード例 #22
0
void KDirWatchTest::allTests()
{
  for(int loop=0; loop<3; ++loop) {
    d = new KDirWatch;
    VERIFY (d != 0);

    QDir* dir = new QDir(m_workingDir);
    VERIFY (dir != 0);

    connect(d, SIGNAL (dirty( const QString &)), SLOT( slotDirty( const QString &)) );
    connect(d, SIGNAL (created( const QString &)), SLOT( slotCreated( const QString &)) );
    connect(d, SIGNAL (deleted( const QString &)), SLOT( slotDeleted( const QString &)) );

    VERIFY (dir->mkdir (m_workingDir));

    d->addDir (m_workingDir);
    VERIFY_NOTHING();
    dir->mkdir ("does");
    VERIFY_DIRTY (m_workingDir);
    touch_file (m_workingDir + "/file");
    VERIFY_DIRTY (m_workingDir);
    VERIFY_NOTHING ();
    remove_file (m_workingDir + "/file");
    d->addDir (m_workingDir + "/does/not/exist");
    d->removeDir (m_workingDir);
    VERIFY_NOTHING();

    dir->mkdir ("does/not");
    VERIFY_NOTHING();
    dir->mkdir ("does/not/exist");
    VERIFY_CREATED (m_workingDir + "/does/not/exist");

    dir->rmdir ("does/not/exist");
    VERIFY_DELETED (m_workingDir + "/does/not/exist");
    dir->rmdir ("does/not");
    VERIFY_NOTHING();
    dir->rmdir ("does");
    VERIFY_NOTHING();

    d->addFile(m_workingDir + "/a");
    touch_file(m_workingDir + "/a");
    VERIFY_CREATED (m_workingDir + "/a");

    rename_file (m_workingDir + "/a", m_workingDir + "/b");
    VERIFY_DELETED (m_workingDir + "/a");
    VERIFY_NOTHING();

    touch_file (m_workingDir + "/a");
    VERIFY_CREATED (m_workingDir + "/a");
    VERIFY_NOTHING();

    touch_file (m_workingDir + "/a");
    VERIFY_DIRTY (m_workingDir + "/a");

    remove_file (m_workingDir + "/b");
    VERIFY_NOTHING();

    d->removeFile(m_workingDir + "/a");

    remove_file(m_workingDir + "/a");

    VERIFY (dir->rmdir (m_workingDir));
    delete d;
  }
}
コード例 #23
0
ファイル: fs-util.c プロジェクト: systemd/systemd-netlogd
int touch(const char *path) {
        return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, MODE_INVALID);
}
コード例 #24
0
ファイル: foo-pre.c プロジェクト: glftpd-scripts/foo-tools
/*
 * Loads a filelist from a dir.
 *
 * Also chowns all files in the dir if chown is != 0.
 */
filelist_t * filelist_find_by_dir(filelist_t *l, char *base, char *path, chowninfo_t *chown) {
	DIR *dh;
	char buf[1024], *group;
	struct dirent *dent;
	struct stat st;
	filelist_t *tmp;

	group = ht_get(get_context(), PROPERTY_GROUP);

	sprintf(buf, "%s/%s", base, path);
	dh = opendir(buf);

	if (!dh)
		return l;

	while ((dent = readdir(dh))) {
		if ((!strcmp(dent->d_name, ".")) ||
		    (!strcmp(dent->d_name, "..")))
			continue;

		sprintf(buf, "%s/%s/%s", base, path, dent->d_name);

		if (stat(buf, &st) == -1)
			continue;

		// chown file
		chowninfo_apply_to_file(buf, chown);

		if (S_ISDIR(st.st_mode)) {

			// touch dir
			touch_dir(buf);

			if (strlen(path) > 0)
				sprintf(buf, "%s/%s", path, dent->d_name);
			else
				strcpy(buf, dent->d_name);

			// find recursively.
			l = filelist_find_by_dir(l, base, buf, chown);

		} else {
			// touch file
			touch_file(buf);

			tmp = (filelist_t*)malloc(sizeof(filelist_t));

			if (strlen(path) > 0)
				sprintf(tmp->file, "%s/%s", path, dent->d_name);
			else
				strcpy(tmp->file, dent->d_name);

			memcpy(&tmp->st, &st, sizeof(st));

			tmp->next = l;

			l = tmp;
		}
	}

	closedir(dh);

	return l;
}
コード例 #25
0
ファイル: main.c プロジェクト: nehayward/FileSystemC
void main(int argc, char *argv[])
{
	int i = 0, cmd = -1, fd = 0; 
	char line[128], cname[64], temp_pathname[124], pathname[124] = "NULL", basename[124] = "NULL",
	     dirname[124] = "NULL", parameter[124] = "NULL", *device;

	//GETS DISK NAME TO MOUNT
	/*
	printf("Enter the name of your disk image\n");
	fgets(device, 128, stdin);
	device[strlen(device)-1] = 0;  // kill the \n char at end	
	*/
	device = "mydisk";
	
	mount_root(device, &fd);

	while(1)
	{
		//printf("P%d running: ", running.uid);
		printf("nick's@linux:");
		pwd(P0.cwd);
		printf("$ ");
		fgets(line, 128, stdin);
		line[strlen(line)-1] = 0;  // kill the \n char at end
		if (line[0]==0) continue;

		sscanf(line, "%s %s %s", cname, pathname, parameter);

		if(strcmp(pathname,"NULL") != 0)		
			strcpy(PATHNAME, pathname);
		
		if(strcmp(parameter,"NULL") != 0)		
			strcpy(PARAMETER, parameter);

		cmd = findCmd(cname); // map cname to an index
		switch(cmd)
		{
			case 0 : menu();		break;
			case 1 : pwd(P0.cwd);printf("\n");			break;
			case 2 : ls();			break;
			case 3 : cd();			break;
			case 4 : make_dir();		break;
			case 5 : rmdir();               break;
			case 6 : creat_file();          break;
			case 7 : link();                break;
			case 8 : unlink();              break;
			case 9 : symlink();             break;
			case 10: rm_file();             break;
			case 11: chmod_file();          break;
			case 12: chown_file();          break;
			case 13: stat_file();           break;
			case 14: touch_file();          break;
			case 20: open_file();           break;		//LEVEL 2
			case 21: close_file((int)PATHNAME);          break;
			case 22: pfd();                 break;
			case 23: lseek_file();          break;
			case 24: //access_file();         break;
				break;
			case 25: //read_file();           
				break;
			case 26: write_file();          break;
			case 27: cat_file();            break;
			case 28: cp_file();             break;
			case 29: mv_file();             break;
			case 30: mount();               break;		//LEVLEL 3
			case 31: //umount();              break;
			case 32: //cs();                  break;
			case 33: //do_fork();             break;
			case 34: //do_ps();               break;
			case 40: //sync();                break; 
			case 41: quit();              	 break;
			case 42 : system("clear");	break; 
			default: printf("invalid command\n");
			break;
			
		}

		//RESET NAMES
		strcpy(parameter, "NULL");
		strcpy(pathname, "NULL");
		strcpy(PATHNAME, "NULL");
	}
	
  }
コード例 #26
0
/**
 * Reads the list of files from the host IDE runs on,
 * creates files, fills internal file table
 */
static int init_files() {
    trace("Files list initialization\n");
    int bufsize = PATH_MAX + 32;
    char buffer[bufsize];
    int success = false;
    file_elem* list = NULL;
    file_elem* tail = NULL;
    start_adding_file_data();
    while (1) {
        if( !fgets(buffer, bufsize, stdin)) {
            report_error("protocol error while reading file info: unexpected EOF\n");
            return false;
        }
        if (buffer[0] == '\n') {
            success = true;
            break;
        }
        trace("\tFile init: %s", buffer); // no trailing LF since it's in the buffer
        // remove trailing LF
        char* lf = strchr(buffer, '\n');
        if (lf) {
            *lf = 0;
        }
        if (strchr(buffer, '\r')) {
            report_error("protocol error: unexpected CR: %s\n", buffer);
            return false;
        }

        enum file_state state;
        int file_size;
        char *path;
        struct timeval file_time;
        file_time.tv_sec = file_time.tv_usec = 0;

        if (!scan_line(buffer, bufsize, &state, &file_size, &file_time, (const char**) &path)) {
            report_error("protocol error: %s\n", buffer);
            break;
        }
        trace("\t\tpath=%s size=%d state=%c (0x%x) time=%d.%d\n", path, file_size, (char) state, (char) state, file_time.tv_sec, file_time.tv_usec);

        if (state == -1) {
            report_error("protocol error: %s\n", buffer);
            break;
        } else if (state == DIRECTORY) { // directory
            create_dir(path);
        } else if (state == LINK) { // symbolic link
            char lnk_src[bufsize]; // it is followed by a line that contains the link source
            if( !fgets(lnk_src, sizeof lnk_src, stdin)) {
                report_error("protocol error while reading link info: unexpected EOF\n");
                return false;
            }
            char* lf = strchr(lnk_src, '\n');
            if (lf) {
                *lf = 0;
            }
            if (strchr(buffer, '\r')) {
                report_error("protocol error: unexpected CR: %s\n", buffer);
                return false;
            }
            create_lnk(path, lnk_src);
        } else { // plain file
            int touch = false;
            if (state == INITIAL) {
                touch = true;
            } else if (state == COPIED || state == TOUCHED) {
                touch = !file_exists(path, file_size);
            } else if (state == UNCONTROLLED || state == INEXISTENT) {
                // nothing
            } else {
                report_error("protocol error: %s\n", buffer);
            }

            enum file_state new_state = state;
            if (touch) {
                if (touch_file(path, file_size, &file_time)) {
                    new_state = TOUCHED;
                } else {
                    new_state = ERROR;
                }
            }

            if (*path == '/') {
                char real_path [PATH_MAX + 1];
                if (state == UNCONTROLLED || state == INEXISTENT) {
                    char *dir = path;
                    char *file = path;
                    // find trailing zero
                    while (*file) {
                        file++;
                    }
                    // we'll find '/' for sure - at least the starting one
                    while(*file != '/') {
                        file--;
                    }
                    if (file == path) { // the file resides in root directory
                        strcpy(real_path, path);
                    } else {
                        // NB: we modify the path! but we'll restore later
                        char *pfile_start = file; // save file start char
                        char file_start = *file;  // save file start char
                        *file = 0; // replace the '/' that separates file from dir by zero
                        file++; 
                        if (!realpath(dir, real_path)) {
                            report_unresolved_path(dir);
                            break;
                        }
                        char *p = real_path;
                        while (*p) {
                            p++;
                        }
                        *(p++) = '/';
                        strncpy(p, file, sizeof real_path - (p - real_path));
                        *pfile_start = file_start; // restore file start char
                    }
                } else {
                    if (!realpath(path, real_path)) {
                       report_unresolved_path(path);
                       break; 
                    }
                }
                trace("\t\tadding %s with state '%c' (0x%x) -> %s\n", path, (char) new_state, (char) new_state, real_path);
                add_file_data(real_path, new_state);
                // send real path to local controller
                tail = add_file_to_list(tail, path, new_state, real_path);
                //trace("\t\tadded to list %s with state '%c' (0x%x) -> %s\n", tail->filename, tail->state, tail->state, tail->real_path);
                if (list == NULL) {
                    list = tail;
                }
            } else {
                report_error("protocol error: %s is not absoulte\n", path);
                break;
            }
        }
    }
    stop_adding_file_data();
    trace("Files list initialization done\n");
    if (success) {
        // send info about touched files which were passed as copied files
        tail = list;
        while (tail != NULL) {
            fprintf(stdout, "*%c%s\n%s\n", tail->state, tail->filename, tail->real_path);
            fflush(stdout);
            tail = tail->next;
        }
        free_file_list(list);
        // empty line as indication of finished files list
        fprintf(stdout, "\n");
        fflush(stdout);
    }
    return success;
}
コード例 #27
0
ファイル: richole.c プロジェクト: RazZziel/wine
static void test_ITextDocument_Open(void)
{
  IRichEditOle *reOle = NULL;
  ITextDocument *txtDoc = NULL;
  ITextSelection *txtSel = NULL;
  HRESULT hres;
  HWND w;
  HANDLE hFile;
  VARIANT testfile;
  WCHAR filename[] = {'t', 'e', 's', 't','.','t','x','t', 0};
  int result;
  DWORD dw;
  static const CHAR chACP[] = "TestSomeText";
  static const CHAR chUTF8[] = "\xef\xbb\xbfTextWithUTF8BOM";
  static const WCHAR chUTF16[] = {0xfeff, 'T', 'e', 's', 't', 'S', 'o', 'm',
                                  'e', 'T', 'e', 'x', 't', 0};

#define MAX_BUF_LEN 1024
  CHAR bufACP[MAX_BUF_LEN];
  WCHAR bufUnicode[MAX_BUF_LEN];

  static const int tomConstantsSingle[] =
    {
      tomReadOnly, tomShareDenyRead, tomShareDenyWrite,
      tomCreateAlways, tomOpenExisting, tomOpenAlways,
      tomTruncateExisting, tomRTF, tomText
    };

  static const int tomConstantsMulti[] =
    {
      tomReadOnly|tomShareDenyRead|tomPasteFile, tomReadOnly|tomPasteFile,
      tomReadOnly|tomShareDenyWrite|tomPasteFile,
      tomReadOnly|tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyWrite|tomPasteFile,
      tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyRead|tomPasteFile,
      tomShareDenyRead|tomShareDenyWrite, tomReadOnly|tomShareDenyRead|tomShareDenyWrite,
      tomReadOnly|tomShareDenyWrite, tomReadOnly|tomShareDenyRead
    };

  int tomNumSingle =  sizeof(tomConstantsSingle)/sizeof(tomConstantsSingle[0]);
  int tomNumMulti = sizeof(tomConstantsMulti)/sizeof(tomConstantsMulti[0]);
  int i;
  VariantInit(&testfile);
  V_VT(&testfile) = VT_BSTR;
  V_BSTR(&testfile) = SysAllocString(filename);

  for(i=0; i < tomNumSingle; i++)
    {
      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_ACP);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
         tomConstantsSingle[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);

      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_UTF8);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
         tomConstantsSingle[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);
    }

  for(i=0; i < tomNumMulti; i++)
    {
      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_ACP);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
         tomConstantsMulti[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);

      touch_file(filename);
      create_interfaces(&w, &reOle, &txtDoc, &txtSel);
      hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_UTF8);
      todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
         tomConstantsMulti[i], hres);
      release_interfaces(&w, &reOle, &txtDoc, &txtSel);
      DeleteFileW(filename);
    }

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_ACP);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_UTF8);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_ACP);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_UTF8);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
  todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
  todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  touch_file(filename);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_ACP\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  touch_file(filename);
  hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_ACP);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_ACP\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_UTF8);
  todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);

  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);
  ITextDocument_Open(txtDoc, &testfile, tomText, CP_ACP);
  todo_wine ok(is_existing_file(filename) == TRUE, "a file should be created default\n");
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  /* test of share mode */
  touch_file(filename);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  ITextDocument_Open(txtDoc, &testfile, tomShareDenyRead, CP_ACP);
  SetLastError(0xdeadbeef);
  hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);
  todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
  CloseHandle(hFile);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  touch_file(filename);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite, CP_ACP);
  SetLastError(0xdeadbeef);
  hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);
  todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
  CloseHandle(hFile);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  touch_file(filename);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  SetLastError(0xdeadbeef);
  ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite|tomShareDenyRead, CP_ACP);
  hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);
  todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
  CloseHandle(hFile);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  /* tests to check the content */
  hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
                      FILE_ATTRIBUTE_NORMAL, NULL);
  WriteFile(hFile, chACP, sizeof(chACP)-sizeof(CHAR), &dw, NULL);
  CloseHandle(hFile);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  ITextDocument_Open(txtDoc, &testfile, tomReadOnly, CP_ACP);
  result = SendMessageA(w, WM_GETTEXT, 1024, (LPARAM)bufACP);
  todo_wine ok(result == 12, "ITextDocument_Open: Test ASCII returned %d, expected 12\n", result);
  result = strcmp(bufACP, chACP);
  todo_wine ok(result == 0, "ITextDocument_Open: Test ASCII set wrong text: Result: %s\n", bufACP);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
                      FILE_ATTRIBUTE_NORMAL, NULL);
  WriteFile(hFile, chUTF8, sizeof(chUTF8)-sizeof(CHAR), &dw, NULL);
  CloseHandle(hFile);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  ITextDocument_Open(txtDoc, &testfile, tomReadOnly, CP_UTF8);
  result = SendMessageA(w, WM_GETTEXT, 1024, (LPARAM)bufACP);
  todo_wine ok(result == 15, "ITextDocument_Open: Test UTF-8 returned %d, expected 15\n", result);
  result = strcmp(bufACP, &chUTF8[3]);
  todo_wine ok(result == 0, "ITextDocument_Open: Test UTF-8 set wrong text: Result: %s\n", bufACP);
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);

  hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
                      FILE_ATTRIBUTE_NORMAL, NULL);
  WriteFile(hFile, chUTF16, sizeof(chUTF16)-sizeof(WCHAR), &dw, NULL);
  CloseHandle(hFile);
  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
  ITextDocument_Open(txtDoc, &testfile, tomReadOnly, 1200);
  result = SendMessageW(w, WM_GETTEXT, 1024, (LPARAM)bufUnicode);
  todo_wine ok(result == 12, "ITextDocument_Open: Test UTF-16 returned %d, expected 12\n", result);
  result = lstrcmpW(bufUnicode, &chUTF16[1]);
  todo_wine ok(result == 0, "ITextDocument_Open: Test UTF-16 set wrong text: Result: %s\n", wine_dbgstr_w(bufUnicode));
  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
  DeleteFileW(filename);
}
コード例 #28
0
ファイル: open.c プロジェクト: jaredm94/File-System
int open_file(char * pathname, int user_mode)
{
    int dev;
    char temp[128];

    if (pathname[0]=='/')
    {
        dev = root->dev;
    }          // root INODE's dev
    else
    {
        dev = running->cwd->dev;
//        strcpy(temp,running->cwd->name);// account for no / not absolute
//
//        if(strcmp(running->cwd->name,"/")==0)
//        {
//        strcat(temp,"/");
//        }
//
//        strcat(temp,pathname);

    }


    // now we get the file loaded into memory
    int mino = getino(dev, pathname); //get the parent ino

    //check its existance.
    if(mino == -1)
    {
        printf("\nERROR: FILE DOESNT EXIST.\n");
        return -1;
    }

    MINODE * mip  = iget(dev, mino); // load the inode into mem

    if(!S_ISREG(mip->INODE.i_mode))
    {
        printf("\nERROR: TRIED TO OPEN SOMETHING OTHER THEN A FILE.\n");
        iput(mip);
        return -1;
    }
    else if(isBusy(mip)==1)
    {
        printf("\nERROR: FILE IS BUSY CAN'T OPEN.\n");
        iput(mip);
        return -1;
    }
    //now we check to see if the file is being altered else where
    int offset = allocateOFT(mip,user_mode);
    /**************** CHECK TO SEEE IF THE FILE IS OPEN ****************/
    if(offset==-1)
    {
        iput(mip);
        return -1;
    }

    // Update directory access time
    touch_file(pathname);

return offset;
    //look for an open spot in the table

}
コード例 #29
0
ファイル: lua_common.c プロジェクト: DUANISTON/forsaken
static int lua_touch_file(lua_State *state)
{
	char* path = (char*) lua_tostring(state,1); // get argument
	touch_file( path );
	return 0; // number of results
}
コード例 #30
0
ファイル: bdb_blockchain.cpp プロジェクト: da2ce7/libbitcoin
bool bdb_blockchain::initialize(const std::string& prefix)
{
    // Try to lock the directory first
    boost::filesystem::path lock_path = prefix;
    lock_path /= "db-lock";
    std::ofstream touch_file(lock_path.native(), std::ios::app);
    touch_file.close();
    flock_ = lock_path.c_str();
    if (!flock_.try_lock())
    {
        // Database already opened elsewhere
        return false;
    }
    // Continue on
    GOOGLE_PROTOBUF_VERIFY_VERSION;
    env_ = new DbEnv(0);
    env_->set_lk_max_locks(10000);
    env_->set_lk_max_objects(10000);
    env_->set_cachesize(1, 0, 1);
    if (env_->open(prefix.c_str(), env_flags, 0) != 0)
        return false;
    // Create database objects
    db_blocks_ = new Db(env_, 0);
    db_blocks_hash_ = new Db(env_, 0);
    db_txs_ = new Db(env_, 0);
    db_spends_ = new Db(env_, 0);
    db_address_ = new Db(env_, 0);
    if (db_blocks_->set_bt_compare(bt_compare_blocks) != 0)
    {
        log_fatal() << "Internal error setting BTREE comparison function";
        return false;
    }
    txn_guard txn(env_);
    if (db_blocks_->open(txn.get(), "blocks", "block-data",
            DB_BTREE, db_flags, 0) != 0)
        return false;
    if (db_blocks_hash_->open(txn.get(), "blocks", "block-hash", 
            DB_BTREE, db_flags, 0) != 0)
        return false;
    db_blocks_->associate(txn.get(), db_blocks_hash_, get_block_hash, 0);
    if (db_txs_->open(txn.get(), "transactions", "tx",
            DB_BTREE, db_flags, 0) != 0)
        return false;
    if (db_spends_->open(txn.get(), "transactions", "spends",
            DB_BTREE, db_flags, 0) != 0)
        return false;
    db_address_->set_flags(DB_DUP);
    if (db_address_->open(txn.get(), "address", "address",
            DB_BTREE, db_flags, 0) != 0)
        return false;
    txn.commit();

    common_ = std::make_shared<bdb_common>(env_,
        db_blocks_, db_blocks_hash_, db_txs_, db_spends_, db_address_);

    orphans_ = std::make_shared<orphans_pool>(20);
    bdb_chain_keeper_ptr chainkeeper = 
        std::make_shared<bdb_chain_keeper>(common_, env_,
            db_blocks_, db_blocks_hash_, db_txs_, db_spends_, db_address_);
    chain_ = chainkeeper;
    organize_ = std::make_shared<bdb_organizer>(
        common_, orphans_, chainkeeper, reorganize_subscriber_);

    return true;
}