fopen

C print file path from FILE*

て烟熏妆下的殇ゞ 提交于 2019-12-29 08:51:07
问题 FILE * fd = fopen ("/tmp/12345","wb"); If I have the variable fd , how can I print the file path ? (/tmp/12345) in Linux env. 回答1: There's no standard way to retrieve a pathname from a FILE * object, mainly because you can have streams that aren't associated with a named file ( stdin , stdout , stderr , pipes, etc.). Individual platforms may supply utilities to retrieve a path from a stream, but you'd have to check the documentation for that platform. Otherwise, you're expected to keep track

How to check if a PHP stream resource is readable or writable?

做~自己de王妃 提交于 2019-12-29 05:46:07
问题 In PHP, how do I check if a stream resource (or file pointer, handle, or whatever you want to call them) is either readable or writable? For example, if you're faced with a situation where you know nothing about how the resource was opened or created, how do you check if it's readable? And how do you check if it's writable? Based on the testing that I've done (just with regular text files using PHP 5.3.3), fread() does not throw any errors at any level when the resource is not readable. It

fopen ,cstdioFile,ifstream速率

回眸只為那壹抹淺笑 提交于 2019-12-26 04:42:42
// TODO: 在此添加控件通知处理程序代码 CString lpszFilePath= _T("C:\\cn.txt"); if (!PathFileExists(lpszFilePath)) return; __int64 nRows = 0, nRows1 = 0, nRows2=0, nRows3 = 0; FILE *fp; int nLen = 1024 * 128; char app1[1024 * 128] = { 0 }; __int64 time_start1 = GetTickCount(); // m_timeCount.Begin(); errno_t _result =_wfopen_s(&fp, lpszFilePath, _T("r")); printf("%d\n", GetLastError()); while (!feof(fp)) { memset(app1, 0x00, nLen); fgets(app1, nLen, fp); nRows++; } printf("%d\n", GetLastError()); fclose(fp); //printf("%s\n", app1); //__int64 nSpan = m_timeCount.End(); __int64 time_start2 = GetTickCount();

PHP adding $ signs into strings without it being a variable? [duplicate]

喜欢而已 提交于 2019-12-25 18:32:16
问题 This question already has answers here : Dollar ($) sign in password string treated as variable (8 answers) Closed 3 years ago . I'm making a setup page where people can write their database login etc and that will then create a config.php file on their webserver with the info but obviously I can't just write $file = fopen("config.php", "w"); fwrite($file, "$dbName = $dbName"); I actually tried $file = fopen("config.php", "w"); fwrite($file, "$" . "dbName = $dbName"); But that doesn't work

PHP fopen function timed out?

给你一囗甜甜゛ 提交于 2019-12-25 16:48:50
问题 any idea why fopen would timeout for a file if it is on my server and I know the url is correct? update: sorry, i should have mentioned this is in php. the code is: fopen($url, 'r'); It works if i put in a relative path for the file, but not if $url is a url in my server (but it works for google.com). Thanks for the help. Alaitnik's answer was right. The problem only appears when i access my own server files through the ethernet interface. How can I fix this? I need to be able to access the

Receiving error code during output redirection using execvp

自闭症网瘾萝莉.ら 提交于 2019-12-25 16:26:16
问题 I am trying to redirect the output from ls to a file, in a shell I created in C. I type in: ls > junk and what I get out is: ls: cannot access >: No such file or directory Then if I use CTRL-D to exit the shell it prints the results of the ls command to the screen before exiting. I tried to use print statements to figure out where it is happening and no print statements get printed after: dup2(f, STDOUT_FILENO); Also tried dup2(f, 1); Code: pid = fork(); if(pid == 0) { // Get the arguments

Receiving error code during output redirection using execvp

感情迁移 提交于 2019-12-25 16:25:14
问题 I am trying to redirect the output from ls to a file, in a shell I created in C. I type in: ls > junk and what I get out is: ls: cannot access >: No such file or directory Then if I use CTRL-D to exit the shell it prints the results of the ls command to the screen before exiting. I tried to use print statements to figure out where it is happening and no print statements get printed after: dup2(f, STDOUT_FILENO); Also tried dup2(f, 1); Code: pid = fork(); if(pid == 0) { // Get the arguments

fopen() function with a dynamic location in C

十年热恋 提交于 2019-12-25 09:39:10
问题 I just want to learn that how can I open a file with fopen() function from a dynamic location. I mean, for example it will be a system file and in another computer, this file can be in another location. So if I will set my location in my code not dynamically, my program will not work in another computer. So how Can I set the location dynamically for my program will find this file wherever it is? 回答1: You can (and often should) pass program arguments to your main , thru the conventional int

PHP Can't Open Network File

此生再无相见时 提交于 2019-12-25 08:27:24
问题 I have a site using PHP scripts running on Windows Server 2012 R2 in IIS. I am trying to use fopen to read a file on another server in our network but am having problems. I am able to use the fopen command to open files on the local server and using the PHP CLI, I can successfully open the file on the remote server. However, when I try to process it via the site using my browser, it fails with the error: "failed to open stream: Permission denied" In IIS, I created a new Application Pool and

php won't create file

倾然丶 夕夏残阳落幕 提交于 2019-12-25 06:39:18
问题 So I tried creating a file with php using fopen(file, w). but it returns an error. However this is only on the server side, it works fine on when I run it on localhost(XAMPP) Code is as follows function createdatafile(){ //Rolls a random number which will be the file name. $x = rand(0, 9999999); $file = "Datafiles/".$x.".csv"; if(!file_exists($file)){ $nfile = fopen($file, "w") or die("cannot create file: $file ");//fails //createdata() just returns a string. However this doesnt even get