本文整理汇总了C++中create_file函数的典型用法代码示例。如果您正苦于以下问题:C++ create_file函数的具体用法?C++ create_file怎么用?C++ create_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_device_alias
int write_device_alias(const char *src, const char *dst, const char *alias)
{
char filename[PATH_MAX + 1];
create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
return textfile_put(filename, dst, alias);
}
示例2: create_fd
int create_fd(const char *arg, int is_output, enum proto *proto, char *name, size_t max_name_size)
{
if (strncmp(arg, "udp:", 4) == 0 || strncmp(arg, "UDP:", 4) == 0) {
*proto = UDP;
arg += 4;
} else if (strncmp(arg, "tcp:", 4) == 0 || strncmp(arg, "TCP:", 4) == 0) {
*proto = TCP;
arg += 4;
} else if (strncmp(arg, "file:", 5) == 0) {
*proto = File;
arg += 5;
} else if (strncmp(arg, "eth:", 4) == 0) {
*proto = Eth;
arg += 4;
} else if (strcmp(arg, "null:") == 0) {
*proto = File;
arg = "/dev/null";
} else if (strcmp(arg, "zero:") == 0) {
*proto = File;
arg = "/dev/zero";
} else if (strcmp(arg, "stdin:") == 0) {
*proto = StdIn;
arg = "stdin";
} else if (strcmp(arg, "stdout:") == 0) {
*proto = StdOut;
arg = "stdout";
} else if (strcmp(arg, "stderr:") == 0) {
*proto = StdErr;
arg = "stderr";
} else if (strchr(arg, ':') != 0) {
*proto = UDP;
} else if (strcmp(arg, "-") == 0) {
*proto = is_output ? StdOut : StdIn;
arg = is_output ? "stdout" : "stdin";
} else {
*proto = File;
}
if (name != 0)
strncpy(name, arg, max_name_size);
switch (*proto) {
case UDP :
case TCP : return create_IP_socket(arg, is_output, *proto);
case File : return create_file(arg, is_output);
case Eth : return create_raw_eth_socket(arg, is_output);
case StdIn :
case StdOut:
case StdErr : return create_stdio(is_output, *proto);
default : fprintf(stderr, "Cannot create fd for unknown proto %d\n", *proto), exit(1);
}
}
示例3: syscall_creat
int syscall_creat(const char *path, mode_t mode)
{
int i, drive;
int curdir_handle, new_handle;
char name_comp[13], conv_name[11], dir_path[501];
if (strlen(path) > 500) return ELONGPATH;
parse_path(path, &drive, dir_path, name_comp);
if (dir_path[0] != 0)
{
curdir_handle = open_path(drive, dir_path);
if (curdir_handle < 0)
return curdir_handle; // Error
}
else
{
curdir_handle = get_curdir_handle(drive);
increment_ref_count(curdir_handle);
}
// Last file name component.
if (convert_name(name_comp, conv_name) < 0)
{
close_dir(curdir_handle);
return EINVALIDNAME; // Error
}
mode = mode & 0x3f; // Valid bits
if (mode == 0) mode = 0x20;
else mode = mode & (~(FTYPE_DIR | FTYPE_VOLUME));
new_handle = create_file(curdir_handle, conv_name, mode);
close_dir(curdir_handle);
for (i=3; i<20; i++)
{
if (fileinf->fhandles[i] < 0)
break;
}
if (i < 20)
{
fileinf->fhandles[i] = new_handle;
new_handle = i;
}
else
{
close_file(new_handle);
new_handle = ENO_FREE_FILE_TABLE_SLOT;
}
return new_handle; // may be failure or success
}
示例4: test_symlink
static int test_symlink(void)
{
char buf[1024];
const char *data = testdata;
int datalen = testdatalen;
int linklen = strlen(testfile);
int err = 0;
int res;
start_test("symlink");
res = create_file(testfile, data, datalen);
if (res == -1)
return -1;
unlink(testfile2);
res = symlink(testfile, testfile2);
if (res == -1) {
PERROR("symlink");
return -1;
}
res = check_type(testfile2, S_IFLNK);
if (res == -1)
return -1;
err += check_mode(testfile2, 0777);
err += check_nlink(testfile2, 1);
res = readlink(testfile2, buf, sizeof(buf));
if (res == -1) {
PERROR("readlink");
err--;
}
if (res != linklen) {
ERROR("short readlink: %u instead of %u", res, linklen);
err--;
}
if (memcmp(buf, testfile, linklen) != 0) {
ERROR("link mismatch");
err--;
}
err += check_size(testfile2, datalen);
err += check_data(testfile2, data, 0, datalen);
res = unlink(testfile2);
if (res == -1) {
PERROR("unlink");
return -1;
}
res = check_nonexist(testfile2);
if (res == -1)
return -1;
if (err)
return -1;
success();
return 0;
}
示例5: save_fournisseur
void save_fournisseur(char* filename, Fournisseur* fournisseur) {
// Avant tout, tester si fournisseur n'est pas NULL
if (!fournisseur) return;
// Créer le fichier s'il n'existe pas
if (!file_exist(filename)) create_file(filename);
// Cherche si le médicament existe
// Si oui, il suffit de modifier le médicament
// Existant, Sinon on crée un nouveau médicament
// Dans la base de donnée
FILE* file = fopen(filename, "r+b");
// Sortir si le fichier ne peux pas s'ouvrir
if (!file) return;
// Itérer
do {
Fournisseur* current_fournisseur = (Fournisseur*)malloc(sizeof(Fournisseur));
if (!fread(current_fournisseur, sizeof(Fournisseur), 1, file)) break;
// Si le médicament est trouvé
if (current_fournisseur -> fournisseur_id == fournisseur -> fournisseur_id) {
// Modifier le médicament
long int currPost = ftell(file);
fseek(file, currPost - sizeof(Fournisseur), SEEK_SET);
fwrite(fournisseur, sizeof(Fournisseur), 1, file);
// Sortir de la fonction
fclose(file);
return;
}
} while (1);
// Trouver le dernier client ajouté
Fournisseur* last_fournisseur = get_last_fournisseur(filename);
// Set nouveau id
int new_id = (last_fournisseur == NULL) ? 1 : last_fournisseur -> fournisseur_id + 1;
// Set nouveau id
fournisseur -> fournisseur_id = new_id;
// Sauvegarder la commande
fwrite(fournisseur, sizeof(Fournisseur), 1, file);
// Fermer le fichier
fclose(file);
}
示例6: output_key
void output_key(char filename[], unsigned char key[], int key_size) {
// http://stackoverflow.com/a/8004250
if (strcmp(filename, "-") != 0) {
FILE *out = create_file(filename);
fwrite(key, key_size, 1, out);
fclose(out);
} else {
fwrite(bytes_to_hex(key, key_size), key_size * 2, 1, stdout);
fputs("\n", stdout);
}
}
示例7: setup
/***************************************************************
* setup() - performs all ONE TIME setup for this test.
***************************************************************/
void setup()
{
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
tst_tmpdir();
create_file();
}
示例8: main
int main(int ac,char *av[])
{
int i=0;
int j=0;
int k=0;
int l=0;
char dir1[MAXN];
char dir2[MAXN];
char dir3[MAXN];
char filename[MAXN];
time_t t;
int maxfiles=0xFFFFFF;
int createfiles=0;
if (ac > 1) {
sscanf(av[1],"%x",&maxfiles);
if (maxfiles==0) {
printf("maxfile argument error (0 value)\n");
exit(1);
}
}
time(&t);
srandom((unsigned int)getpid()^(((unsigned int)t<<16)| (unsigned int)t>>16));
printf("Create files\n");
for (i = 0 ; i < 0xFF ; i++) {
sprintf(dir1,"%2.2x",i);
makedir(dir1);
changedir(dir1);
for (j = 0 ; j < 0xFF ; j++) {
sprintf(dir2,"%2.2x",j);
makedir(dir2);
changedir(dir2);
for (k = 0 ; k < 0xFF ; k++) {
sprintf(dir3,"%2.2x",k);
makedir(dir3);
changedir(dir3);
for (l = 0 ; l < 0xFF ; l++) {
sprintf(filename,"%s%s%s%2.2x",dir1,dir2,dir3,l);
create_file(filename);
if (maxfiles < createfiles++) {
goto end;
}
}
changedir("../");
}
changedir("../");
}
changedir("../");
}
end:
fprintf(stderr,"\nTotal create files: %d\n",filecount);
printf("Done\n");
return 0;
}
示例9: mess_up_inode_field
void mess_up_inode_field(ocfs2_filesys *fs, enum fsck_type type, uint64_t blkno)
{
errcode_t ret;
uint64_t tmpblkno;
uint32_t clusters = 10;
char *buf = NULL;
struct ocfs2_dinode *di;
create_file(fs, blkno, &tmpblkno);
if ((type == INODE_SPARSE_SIZE) || (type == INODE_SPARSE_CLUSTERS)) {
if (!ocfs2_sparse_alloc(OCFS2_RAW_SB(fs->fs_super)))
FSWRK_FATAL("should specfiy a sparse file supported "
"volume to do this corruption\n");
ret = ocfs2_malloc_block(fs->fs_io, &buf);
if (ret)
FSWRK_COM_FATAL(progname, ret);
ret = ocfs2_read_inode(fs, tmpblkno, buf);
if (ret)
FSWRK_COM_FATAL(progname, ret);
di = (struct ocfs2_dinode *)buf;
di->i_size = fs->fs_clustersize * 2;
ret = ocfs2_write_inode(fs, tmpblkno, buf);
if (ret)
FSWRK_COM_FATAL(progname, ret);
if (buf)
ocfs2_free(&buf);
}
if ((type == INODE_CLUSTERS) || (type == INODE_SPARSE_CLUSTERS) ||
(type == INODE_SPARSE_SIZE)) {
ret = ocfs2_extend_allocation(fs, tmpblkno, clusters);
if (ret)
FSWRK_COM_FATAL(progname, ret);
}
if (type == REFCOUNT_FLAG_INVALID &&
ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
FSWRK_FATAL("should specfiy a norefcount volume\n");
if (type == REFCOUNT_LOC_INVALID &&
!ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
FSWRK_FATAL("Should specify a refcount supported volume\n");
damage_inode(fs, tmpblkno, type);
return;
}
示例10: main
int main(){
num_small = (N_SMALL * MAX_SIZE) / SMALL;
num_med = (N_MED * MAX_SIZE) / MED;
num_large = (N_LARGE * MAX_SIZE) / LARGE;
num_huge = (N_HUGE * MAX_SIZE) / HUGE;
int i;
FILE* nfile = fopen("./numbers.txt", "w");
printf("creating %d small files\n", num_small);
fprintf(nfile, "%f\t%d\n", N_SMALL, num_small);
for(i = 0; i< num_small; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/small/small%d", i);
create_file(path, SMALL);
}
printf("creating %d med files\n", num_med);
fprintf(nfile, "%f\t%d\n", N_MED, num_med);
for(i = 0; i< num_med; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/med/med%d", i);
create_file(path, MED);
}
printf("creating %d large files\n", num_large);
fprintf(nfile, "%f\t%d\n", N_LARGE, num_large);
for(i = 0; i< num_large; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/large/large%d", i);
create_file(path, LARGE);
}
printf("creating %d huge files\n", num_huge);
fprintf(nfile, "%f\t%d\n", N_HUGE, num_huge);
for(i = 0; i< num_huge; i++){
char path[256];
sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/huge/huge%d", i);
create_file(path, HUGE);
}
fclose(nfile);
}
示例11: fat_dev_create_file
int fat_dev_create_file(fat_dev_t * pdev, const char * fname)
{
assert(pdev && fname);
pdev->fname = fname; // by gushui
pdev->flag = O_CREAT|O_RDWR;// by gushui
//fat_dev_init(pdev, fname, O_CREAT|O_RDWR); // by gushui
if( 0 > create_file(pdev, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)){
FAT_ERROR("create file failed! err:%s\n", strerror(errno));
return -1;
}
return 0;
}
示例12: main
int main(int argc, char ** argv) {
char * pwd = "."; /* TODO: Fetch the actual path */
file_t * file = create_file(pwd, NEW_FILE);
while(!file->term_status->quit_fl) {
key_handle(file);
render_all(file);
}
close_file(file);
return 0;
}
示例13: refresh_relax_callback
static void refresh_relax_callback(NautilusMenuItem* item,
gpointer user_data)
{
g_print("now refreshing...");
char* refresh_text = "refreshing...";
int fd = create_file("/.relax-refresh");
if(fd != -1)
write(fd, refresh_text, strlen(refresh_text));
close(fd);
}
示例14: footer
int footer()
{
FILE *file;
char *dt;
file = create_file();
dt = date_and_time();
fwrite("\nScript done on ", 17, sizeof(char), file);
fwrite(dt, strlen(dt), sizeof(char), file);
fwrite("\n", 1, sizeof(char), file);
return (0);
}
示例15: header
int header()
{
FILE *file;
char *dt;
file = create_file();
dt = date_and_time();
fwrite("\nScript started on ", 18, sizeof(char), file);
fwrite(dt, strlen(dt), sizeof(char), file);
fwrite("\n", 1, sizeof(char), file);
return (0);
}