Hello i have little problem, i just started with C and download CLion. Everything is ok before i changed file. On the previous version of file was something like
int c;
c=getchar()
putchar(c);
Now i changed file to
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n') {
++nl;
}
if (c == ' ' || c == '\n' || c == '\t') {
state = OUT;
} else if (state == OUT) {
state = IN;
++nw;
}
}
printf("%d %d %d\n", nl, nw, nc);
But after build and run console is like using first version(getchar and putchar). When i run program from directory normal is looks good. I think i need change some configuration but cant find any solution. using "clean" on Run didnt help. Is funny because after create new project is still previous program output :DD
You can try Tools->Cmake->Reload Cmake Project
Related
I face some troubles about PKCS#11 library.
I create 2 projects:
Project 1: macOS Application (GUI - with Objective-C)
Project 2: Command line tool (Console - with C++)
unsigned long GetTokenInfos(CK_TOKEN_INFO_PTR pTokenInfo)
{
CK_RV rv = CKR_OK;
CK_ULONG ulCount = 0;
CK_SLOT_ID_PTR pSlotList = NULL_PTR;
rv = m_pToken->C_GetSlotList(TRUE, NULL_PTR, &ulCount);
if(rv != CKR_OK){
return rv;
}
if(ulCount <= 0){
return CKR_TOKEN_NOT_PRESENT;
}
pSlotList = (CK_SLOT_ID_PTR)new CK_SLOT_ID [ulCount];
rv = m_pToken->C_GetSlotList(TRUE, pSlotList, &ulCount);
if((rv != CKR_OK) || (ulCount <= 0))
{
delete [] pSlotList;
pSlotList = NULL_PTR;
return CKR_TOKEN_NOT_PRESENT;
}
/*Get slot information for the first token*/
for (unsigned int i = 0; i < ulCount; ++i)
{
rv = m_pToken->C_GetTokenInfo(pSlotList[i], pTokenInfo);
if(rv != CKR_OK)
{
delete [] pSlotList;
pSlotList = NULL_PTR;
return rv;
}
//ShowTokenInfo(pTokenInfo);
}
delete [] pSlotList;
pSlotList = NULL_PTR;
return CKR_OK;
}
Both of them follow the same logic and flow of coding; build and run on a computer.
But I got a strange thing:
**Project macOS Application always return zero slot with HSM Token presented, on other side, project Command Line Tool always return one slot with token represented. **
I have no idea about the problem. I guess the macOS application project need some permissions or some things like that, in order to interact with hardware like HSM Token/ Smart Card...
Anyone had experience about the situation? Please give me some advice!
Thank you all!
I'm attempting to save the uboot environment to the FAT partition of an mmc device on a CM3 rpi module. The OS has been built in buildroot I can printenv and this shows the inbuilt env in the binary. The saveenv command is recognised, firstly states it's saving to fat and the filename is uboot-env.bin. The file exists and is found but the function bcm2835_transfer_block_pio seems to write nothing and repeatedly spits out fsm 1, hsts 000001. The mmc is selected as dev0 partition1 (0:1) in buildroot. Anyone come across this error and know how to fix it?
Source for mmc driver:
static int bcm2835_transfer_block_pio(struct bcm2835_host *host, bool is_read)
{
struct mmc_data *data = host->data;
size_t blksize = data->blocksize;
int copy_words;
u32 hsts = 0;
u32 *buf;
if (blksize % sizeof(u32))
return -EINVAL;
buf = is_read ? (u32 *)data->dest : (u32 *)data->src;
if (is_read)
data->dest += blksize;
else
data->src += blksize;
copy_words = blksize / sizeof(u32);
/*
* Copy all contents from/to the FIFO as far as it reaches,
* then wait for it to fill/empty again and rewind.
*/
while (copy_words) {
int burst_words, words;
u32 edm;
burst_words = min(SDDATA_FIFO_PIO_BURST, copy_words);
edm = readl(host->ioaddr + SDEDM);
if (is_read)
words = edm_fifo_fill(edm);
else
words = SDDATA_FIFO_WORDS - edm_fifo_fill(edm);
if (words < burst_words) {
int fsm_state = (edm & SDEDM_FSM_MASK);
if ((is_read &&
(fsm_state != SDEDM_FSM_READDATA &&
fsm_state != SDEDM_FSM_READWAIT &&
fsm_state != SDEDM_FSM_READCRC)) ||
(!is_read &&
(fsm_state != SDEDM_FSM_WRITEDATA &&
fsm_state != SDEDM_FSM_WRITESTART1 &&
fsm_state != SDEDM_FSM_WRITESTART2))) {
hsts = readl(host->ioaddr + SDHSTS);
printf("fsm %x, hsts %08x\n", fsm_state, hsts);
if (hsts & SDHSTS_ERROR_MASK)
break;
}
continue;
} else if (words > copy_words) {
words = copy_words;
}
copy_words -= words;
/* Copy current chunk to/from the FIFO */
while (words) {
if (is_read)
*(buf++) = readl(host->ioaddr + SDDATA);
else
writel(*(buf++), host->ioaddr + SDDATA);
words--;
}
}
return 0;
}
Please correct the below code:only.
file already contains entries : 1st row username; 2nd row password.
checkbox status required to write to the third line and need to read or alter only the checkbox status value in the file.
Currently this code is working if there already is a value for the checkbox status value, then it is overwriting, else UI is hanging.
WriteCheckStatusToFile(BOOL& locVar)
{
FILE *l_pFile = NULL;
CString l_strRememberCheck;
l_strRememberCheck = GetExePath() + _T("password");
CString sVar;
sVar.Format(_T("%d"),locVar);
if(NULL != (l_pFile = fopen(l_strRememberCheck, _T("r+"))) )
{
int count = 0;
char c;
while(count != 2)
{
if((c = fgetc(l_pFile)) == '\n') count++;
}
fseek(l_pFile,ftell(l_pFile),SEEK_SET);
fprintf(l_pFile, sVar);
}
l_strRememberCheck.ReleaseBuffer();
fclose(l_pFile);
}
thanks in advance to all!
sam.
This line
fprintf(l_pFile, sVar);
doesn't look right. I think it should be
fprintf(l_pFile, "%s\n", (LPCTSTR) sVar);
The loop could become infinite if the file has less than two linefeeds:
while(count != 2)
I think it should be:
while( (count < 2) && ( ! feof(l_pFile) ) && ( c != EOF ) )
Probably unrelated to your error, but - at least for this code snippet - CString::ReleaseBuffer() doesn't need to be called since you have not called CString::GetBuffer().
l_strRememberCheck.ReleaseBuffer();
This line may be unnecessary as it appears to fseek() to where the file pointer already is:
fseek(l_pFile,ftell(l_pFile),SEEK_SET);
In the event a two-line file is not terminated with a '\n' you would need to print like this:
if ( count == 2 )
{
fprintf(l_pFile, "%s\n", (LPCTSTR) sVar);
}
else
{
fprintf(l_pFile, "\n%s\n", (LPCTSTR) sVar);
}
I got a relatively simple question.
I have a few mac applications that have launchers written in bash.
I wanted to add a little feature to the launchers, by letting others access a config.app or something else located in /Contents/Resources, when they press the 'option/alt' key at the startup of the app. Kinda like iTunes or iPhoto, where you can access a little options menu.
I don't know how the code should look like when it's purely in bash; i found a few examples that make use of applescript and/or cocoa hooks, but none purely in bash.
Something like: if 'optionKeyDown'; then open "$WORKDIR/../Resources/config.app"
Or is this not possible in pure bash at all?
There's a good solution here: http://lists.apple.com/archives/applescript-users/2009/Sep/msg00374.html
Take the following code:
#import <Carbon/Carbon.h>
int main (int argc, const char * argv[]) {
unsigned int modifiers = GetCurrentKeyModifiers();
if (argc == 1)
printf("%d\n", modifiers);
else {
int i, result = 1;
for (i = 1; i < argc; ++i) {
if (0 == strcmp(argv[i], "shift"))
result = result && (modifiers & shiftKey);
else if (0 == strcmp(argv[i], "option"))
result = result && (modifiers & optionKey);
else if (0 == strcmp(argv[i], "cmd"))
result = result && (modifiers & cmdKey);
else if (0 == strcmp(argv[i], "control"))
result = result && (modifiers & controlKey);
else if (0 == strcmp(argv[i], "capslock"))
result = result && (modifiers & alphaLock);
}
printf("%d\n", result);
}
return 0;
}
Paste it into a file called, e.g. keys.m.
Then build a command line utility like this:
$ gcc keys.m -framework Carbon -o keys
Put the keys executable somewhere in your path, e.g. /usr/local/bin, or even just in the same directory as your bash script, then you can call it as e.g. keys option and check the returned string for "0" or "1".
I'm been trying to poll from a set of named-pipes for a little while now and i keep getting an immediate response of POLLNVAL on any named pipe file descriptor. After finding this blog post about broken polling in OS X I'm pretty certain that this is a b-u-g bug in OS X.
I'm already planning on switching my code to using UDP sockets, but i wanted to ask SO for verification about this a) so that I'm sure it's really broken, and b) for documentation purposes.
Here is a stripped down version of the code I wrote (although the code in the link above, which I tested, spells it out pretty well):
#includes
...
....
#
static const char* first_fifo_path = "/tmp/fifo1";
static const char* second_fifo_path = "/tmp/fifo2";
int setup_read_fifo(const char* path){
int fifo_fd = -1;
if( mkfifo(path, S_IRWXU | S_IRWXG | S_IRWXO) )
perror("error calling mkfifo()... already exists?\n");
if((fifo_fd = open(path, O_RDONLY | O_NDELAY)) < 0)
perror("error calling open()");
return fifo_fd;
}
void do_poll(int fd1, int fd2){
char inbuf[1024];
int num_fds = 2;
struct pollfd fds[num_fds];
int timeout_msecs = 500;
fds[0].fd = fd1;
fds[1].fd = fd2;
fds[0].events = POLLIN;
fds[1].events = POLLIN;
int ret;
while((ret = poll(fds, num_fds, timeout_msecs)) >= 0){
if(ret < 0){
printf("Error occured when polling\n");
printf("ret %d, errno %d\n", ret, errno);
printf("revents = %xh : %xh \n\n", fds[0].revents, fds[1].revents);
}
if(ret == 0){
printf("Timeout Occurred\n");
continue;
}
for(int i = 0; i< num_fds; i++){
if(int event = fds[i].revents){
if(event & POLLHUP)
printf("Pollhup\n");
if(event & POLLERR)
printf("POLLERR\n");
if(event & POLLNVAL)
printf("POLLNVAL\n");
if(event & POLLIN){
read(fds[i].fd, inbuf, sizeof(inbuf));
printf("Received: %s", inbuf);
}
}
}
}
}
int main (int argc, char * const argv[]) {
do_poll(setup_read_fifo(first_fifo_path), setup_read_fifo(second_fifo_path));
return 0;
}
this outputs:
$ ./executive
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
POLLNVAL
...
ad nauseam.
Anybody else run into this? This is a real bug right?
This seems to be a genuine bug. It works as expected on Linux and OpenBSD and fails as you describe on OS X.
OSX 10.4.1, I can confirm the behaviour. The same code works fine (as long as timeout messages are fine) on Linux. All the evidence, including this - http://www.virtualbox.de/changeset/12347 - suggests that there is a real problem.
Yup, known bug. I think the poll breakage is only since 10.4, we had to deal with it in Fink. Glib's configure.in has a test for this, so you can be sure that you're not imagining it. (Well, not precisely this, glib tests for poll on devices, not fifos.)